Skip to content

Commit

Permalink
Add --all param to export:
Browse files Browse the repository at this point in the history
this permit a full copy of entire backups to
other file system
  • Loading branch information
MatteoGuadrini committed Sep 2, 2019
1 parent a02c1b3 commit ed5998a
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 39 deletions.
3 changes: 2 additions & 1 deletion bb.man
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Manpage for Butterfly Backup.
.\" Contact [email protected] to correct errors or typos.
.TH man 1 "29 Aug 2019" "1.7.2" "bb man page"
.TH man 1 "2 Sep 2019" "1.8.0" "bb man page"
.SH NAME
bb \- Butterfly Backup - backup/restore/archive tool , agentless
.SH SYNOPSIS
Expand Down Expand Up @@ -131,6 +131,7 @@ Deploy configuration:
Folder where is catalog file
--backup-id ID, -i ID
Backup-id of backup
--all, -A All backup
--destination DESTINATION, -d DESTINATION
Destination path
--mirror, -m Mirror mode
Expand Down
85 changes: 53 additions & 32 deletions bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from utility import print_verbose

# region Global Variables
VERSION = '1.7.3'
VERSION = '1.8.0'


# endregion
Expand Down Expand Up @@ -439,6 +439,9 @@ def compose_command(flags, host):
# Set ssh custom port
if flags.port:
command.append('--rsh "ssh -p {0}"'.format(flags.port))
# No copy symbolic link
if flags.all:
command.append('--safe-links')
# Set dry-run mode
if flags.dry_run:
command.append('--dry-run')
Expand Down Expand Up @@ -1132,7 +1135,9 @@ def parse_arguments():
group_export = export_action.add_argument_group(title='Export options')
group_export.add_argument('--catalog', '-C', help='Folder where is catalog file', dest='catalog', action='store',
required=True)
group_export.add_argument('--backup-id', '-i', help='Backup-id of backup', dest='id', action='store', required=True)
group_export_id_or_all = group_export.add_mutually_exclusive_group()
group_export_id_or_all.add_argument('--backup-id', '-i', help='Backup-id of backup', dest='id', action='store')
group_export_id_or_all.add_argument('--all', '-A', help='All backup', dest='all', action='store_true')
group_export.add_argument('--destination', '-d', help='Destination path', dest='destination', action='store',
required=True)
group_export.add_argument('--mirror', '-m', help='Mirror mode', dest='mirror', action='store_true')
Expand Down Expand Up @@ -1562,40 +1567,56 @@ def parse_arguments():
if args.action == 'export':
cmds = list()
# Read catalog file
export_catalog = read_catalog(os.path.join(args.catalog, '.catalog.cfg'))
# Check specified argument backup-id
if not export_catalog.has_section(args.id):
print(utility.PrintColor.RED +
'ERROR: Backup-id {0} not exist!'.format(args.id)
+ utility.PrintColor.END)
exit(1)
print_verbose(args.verbose, 'Export backup with id {0}'.format(args.id))
# Log info
log_args = {
'hostname': export_catalog[args.id]['Name'],
'status': args.log,
'destination': os.path.join(export_catalog[args.id]['Path'], 'export.log')
}
catalog_path = os.path.join(args.catalog, '.catalog.cfg')
if os.path.exists(export_catalog[args.id]['Path']) and os.path.exists(args.destination):
# Export
utility.write_log(log_args['status'], log_args['destination'], 'INFO',
'Export {0}. Folder {1} to {2}'.format(args.id, export_catalog[args.id]['Path'],
args.destination))
export_catalog = read_catalog(catalog_path)
if os.path.exists(args.destination):
# Compose command
print_verbose(args.verbose, 'Build a rsync command')
logs = list()
logs.append(log_args)
cmd = compose_command(args, None)
# Add source
cmd.append('{}'.format(export_catalog[args.id]['Path']))
# Add destination
cmd.append('{}'.format(os.path.join(args.destination, export_catalog[args.id]['Name'])))
utility.write_log(log_args['status'], log_args['destination'], 'INFO',
'Export command {0}.'.format(" ".join(cmd)))
# Check cut option
if args.cut:
write_catalog(os.path.join(args.catalog, '.catalog.cfg'), args.id, 'cleaned', 'True')
# Check one export or all
if args.all:
# Log info
log_args = {
'hostname': 'all_backup',
'status': args.log,
'destination': os.path.join(args.destination, 'export.log')
}
logs = list()
logs.append(log_args)
# Add source
cmd.append('{}'.format(os.path.join(args.catalog, '')))
# Add destination
cmd.append('{}'.format(args.destination))
else:
# Log info
log_args = {
'hostname': export_catalog[args.id]['Name'],
'status': args.log,
'destination': os.path.join(export_catalog[args.id]['Path'], 'export.log')
}
logs = list()
logs.append(log_args)
# Check specified argument backup-id
if not export_catalog.has_section(args.id):
print(utility.PrintColor.RED +
'ERROR: Backup-id {0} not exist!'.format(args.id)
+ utility.PrintColor.END)
exit(1)
# Export
utility.write_log(log_args['status'], log_args['destination'], 'INFO',
'Export {0}. Folder {1} to {2}'.format(args.id, export_catalog[args.id]['Path'],
args.destination))
print_verbose(args.verbose, 'Export backup with id {0}'.format(args.id))
if os.path.exists(export_catalog[args.id]['Path']):
# Add source
cmd.append('{}'.format(export_catalog[args.id]['Path']))
# Add destination
cmd.append('{}'.format(os.path.join(args.destination, export_catalog[args.id]['Name'])))
utility.write_log(log_args['status'], log_args['destination'], 'INFO',
'Export command {0}.'.format(" ".join(cmd)))
# Check cut option
if args.cut:
write_catalog(os.path.join(args.catalog, '.catalog.cfg'), args.id, 'cleaned', 'True')
# Start export
cmds.append(' '.join(cmd))
run_in_parallel(start_process, cmds, 1)
Expand Down
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
21 changes: 19 additions & 2 deletions docs/build/html/_sources/index.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ The export function is used to copy a particular backup to another path.
arthur@heartofgold$ bb export -h
usage: bb export [-h] [--verbose] [--log] [--dry-run] --catalog CATALOG
--backup-id ID --destination DESTINATION [--mirror] [--cut]
[--include INCLUDE [INCLUDE ...] | --exclude EXCLUDE
[--backup-id ID | --all] --destination DESTINATION [--mirror]
[--cut] [--include INCLUDE [INCLUDE ...] | --exclude EXCLUDE
[EXCLUDE ...]] [--timeout TIMEOUT] [--skip-error]
[--rsync-path RSYNC] [--bwlimit BWLIMIT] [--ssh-port PORT]
Expand All @@ -900,6 +900,7 @@ The export function is used to copy a particular backup to another path.
Folder where is catalog file
--backup-id ID, -i ID
Backup-id of backup
--all, -A All backup
--destination DESTINATION, -d DESTINATION
Destination path
--mirror, -m Mirror mode
Expand All @@ -919,9 +920,11 @@ The export function is used to copy a particular backup to another path.
Custom ssh port.
* **Export options**
--catalog, -C Select the backups folder (root).
--backup-id, -i Select backup id in the catalog.
--all, -A All backup
--destination, -d Destination path.
--mirror, -m Mirror backup on destination.
--cut, -c Delete source like a move.
Expand All @@ -942,6 +945,19 @@ Export a backup in other directory:
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Export all backup in other directory:
.. code-block:: bash
arthur@heartofgold$ bb export --catalog /mnt/backup/ --all --destination /mnt/backup/export --verbose
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Expand All @@ -953,6 +969,7 @@ Export a backup with exclude pdf files:
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP --exclude=*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP --exclude=*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Expand Down
21 changes: 19 additions & 2 deletions docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,8 @@ <h3>Cygwin on Windows<a class="headerlink" href="#cygwin-on-windows" title="Perm
<p>The export function is used to copy a particular backup to another path.</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>arthur@heartofgold$ bb <span class="nb">export</span> -h
usage: bb <span class="nb">export</span> <span class="o">[</span>-h<span class="o">]</span> <span class="o">[</span>--verbose<span class="o">]</span> <span class="o">[</span>--log<span class="o">]</span> <span class="o">[</span>--dry-run<span class="o">]</span> --catalog CATALOG
--backup-id ID --destination DESTINATION <span class="o">[</span>--mirror<span class="o">]</span> <span class="o">[</span>--cut<span class="o">]</span>
<span class="o">[</span>--include INCLUDE <span class="o">[</span>INCLUDE ...<span class="o">]</span> <span class="p">|</span> --exclude EXCLUDE
<span class="o">[</span>--backup-id ID <span class="p">|</span> --all<span class="o">]</span> --destination DESTINATION <span class="o">[</span>--mirror<span class="o">]</span>
<span class="o">[</span>--cut<span class="o">]</span> <span class="o">[</span>--include INCLUDE <span class="o">[</span>INCLUDE ...<span class="o">]</span> <span class="p">|</span> --exclude EXCLUDE
<span class="o">[</span>EXCLUDE ...<span class="o">]]</span> <span class="o">[</span>--timeout TIMEOUT<span class="o">]</span> <span class="o">[</span>--skip-error<span class="o">]</span>
<span class="o">[</span>--rsync-path RSYNC<span class="o">]</span> <span class="o">[</span>--bwlimit BWLIMIT<span class="o">]</span> <span class="o">[</span>--ssh-port PORT<span class="o">]</span>

Expand All @@ -1190,6 +1190,7 @@ <h3>Cygwin on Windows<a class="headerlink" href="#cygwin-on-windows" title="Perm
Folder where is catalog file
--backup-id ID, -i ID
Backup-id of backup
--all, -A All backup
--destination DESTINATION, -d DESTINATION
Destination path
--mirror, -m Mirror mode
Expand Down Expand Up @@ -1225,6 +1226,10 @@ <h3>Cygwin on Windows<a class="headerlink" href="#cygwin-on-windows" title="Perm
</tr>
<tr><td>&#160;</td><td><p class="first last">Select backup id in the catalog.</p>
</td></tr>
<tr><td class="option-group">
<kbd><span class="option">--all</span>, <span class="option">-A</span></kbd></td>
<td><p class="first last">All backup</p>
</td></tr>
<tr><td class="option-group" colspan="2">
<kbd><span class="option">--destination</span>, <span class="option">-d</span></kbd></td>
</tr>
Expand Down Expand Up @@ -1283,6 +1288,17 @@ <h3>Cygwin on Windows<a class="headerlink" href="#cygwin-on-windows" title="Perm
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync <span class="nb">command</span>
Start <span class="nb">export</span> host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
</pre></div>
</div>
<p>Export all backup in other directory:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>arthur@heartofgold$ bb <span class="nb">export</span> --catalog /mnt/backup/ --all --destination /mnt/backup/export --verbose
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync <span class="nb">command</span>
Start <span class="nb">export</span> host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
</pre></div>
Expand All @@ -1292,6 +1308,7 @@ <h3>Cygwin on Windows<a class="headerlink" href="#cygwin-on-windows" title="Perm
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync <span class="nb">command</span>
Start <span class="nb">export</span> host1
...
INFO: rsync command: rsync -ah --no-links -vP --exclude<span class="o">=</span>*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP --exclude<span class="o">=</span>*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
</pre></div>
Expand Down
21 changes: 19 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ The export function is used to copy a particular backup to another path.
arthur@heartofgold$ bb export -h
usage: bb export [-h] [--verbose] [--log] [--dry-run] --catalog CATALOG
--backup-id ID --destination DESTINATION [--mirror] [--cut]
[--include INCLUDE [INCLUDE ...] | --exclude EXCLUDE
[--backup-id ID | --all] --destination DESTINATION [--mirror]
[--cut] [--include INCLUDE [INCLUDE ...] | --exclude EXCLUDE
[EXCLUDE ...]] [--timeout TIMEOUT] [--skip-error]
[--rsync-path RSYNC] [--bwlimit BWLIMIT] [--ssh-port PORT]
Expand All @@ -900,6 +900,7 @@ The export function is used to copy a particular backup to another path.
Folder where is catalog file
--backup-id ID, -i ID
Backup-id of backup
--all, -A All backup
--destination DESTINATION, -d DESTINATION
Destination path
--mirror, -m Mirror mode
Expand All @@ -919,9 +920,11 @@ The export function is used to copy a particular backup to another path.
Custom ssh port.
* **Export options**
--catalog, -C Select the backups folder (root).
--backup-id, -i Select backup id in the catalog.
--all, -A All backup
--destination, -d Destination path.
--mirror, -m Mirror backup on destination.
--cut, -c Delete source like a move.
Expand All @@ -942,6 +945,19 @@ Export a backup in other directory:
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Export all backup in other directory:
.. code-block:: bash
arthur@heartofgold$ bb export --catalog /mnt/backup/ --all --destination /mnt/backup/export --verbose
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Expand All @@ -953,6 +969,7 @@ Export a backup with exclude pdf files:
INFO: Export backup with id f0f700e8-0435-11e9-9e78-005056a664e0
INFO: Build a rsync command
Start export host1
...
INFO: rsync command: rsync -ah --no-links -vP --exclude=*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
SUCCESS: Command rsync -ah --no-links -vP --exclude=*.pdf /mnt/backup/host1/2018_12_20__10_02 /mnt/backup/export/host1
Expand Down

0 comments on commit ed5998a

Please sign in to comment.