Skip to content

Commit

Permalink
Add backup/restore function:
Browse files Browse the repository at this point in the history
--rsync; select custom rsync binary
Add config function:
--init; reset catalog backup file
  • Loading branch information
MatteoGuadrini committed May 10, 2019
1 parent 89c9d64 commit 179a4ff
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 117 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
![Greta oto](img/bb.png)

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7fc47024f17f4dffa3be08a7a5ab31bd)](https://app.codacy.com/app/MatteoGuadrini/Butterfly-Backup?utm_source=github.com&utm_medium=referral&utm_content=MatteoGuadrini/Butterfly-Backup&utm_campaign=Badge_Grade_Dashboard)

# Butterfly Backup: presentation
**The plan is great when the backup plan is excellent!**

Expand Down Expand Up @@ -61,7 +63,7 @@ bb --help
```

### Backup machine
Backup a single PC or server is a everyday task.
Backup a single PC or server is a everyday task.
But most of the data may not change in the various backups made;
then, in these cases, an incremental backup is needed.
Butterfly Backup natively supports incremental and differential backups, starting from a full.
Expand All @@ -78,7 +80,7 @@ So we created a first _Full_ backup, on a _MacOS_ machine, considering the folde
Now that we have our first Full backup, we can run _incremental_ for the next few times.
```bash
bb backup --computer pc1 --destination /nas/mybackup --data User Config --type MacOS
bb backup --computer pc1 --destination /nas/mybackup --data User Config --type MacOS
```
or with short option:
```bash
Expand Down Expand Up @@ -162,5 +164,13 @@ Butterfly Backup is a open source project. Any contribute, It's welcome.

For donations, press this

[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7fc47024f17f4dffa3be08a7a5ab31bd)](https://app.codacy.com/app/MatteoGuadrini/Butterfly-Backup?utm_source=github.com&utm_medium=referral&utm_content=MatteoGuadrini/Butterfly-Backup&utm_campaign=Badge_Grade_Dashboard)
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/guos)
For me

[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/guos)

For [Telethon](http://www.telethon.it/)
The Telethon Foundation is a non-profit organization recognized by the Ministry of University and Scientific and Technological Research.
They were born in 1990 to respond to the appeal of patients suffering from rare diseases.
Come today, we are organized to dare to listen to them and answers, every day of the year.

<a href="https://dona.telethon.it/it/dona-ora"> <img src="http://www.telethon.it/sites/all/themes/telethon/images/svg/logo.svg" alt="Telethon" title="Telethon" width="200" height="104" /> </a>
31 changes: 19 additions & 12 deletions 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 "11 Dec 2018" "1.4.0" "bb man page"
.TH man 1 "10 May 2019" "1.5.0" "bb man page"
.SH NAME
bb \- Butterfly Backup - backup/restore/archive tool , agentless
.SH SYNOPSIS
Expand All @@ -9,7 +9,7 @@ bb [ACTION] [OPTIONS]
bb [-h] [--verbose] [--log] [--dry-run] [--version]
{config,backup,restore,archive,list,export} ...
.SH DESCRIPTION
Butterfly Backup is a simple command line wrapper of rsync for complex task, written in python.
Butterfly Backup is a simple command line wrapper of rsync for complex task, written in python.
.SH OPTIONS
.TP
action:
Expand Down Expand Up @@ -50,8 +50,9 @@ action:
--timeout TIMEOUT, -T TIMEOUT
I/O timeout in seconds
--skip-error, -e Skip error.
--rsync-path, -R Select a custom rsync path.

.B list
.B list
[ACTION]

--catalog CATALOG, -C CATALOG
Expand All @@ -64,39 +65,41 @@ action:
List only match hostname or ip
--oneline, -o One line output

.B restore
.B restore
[ACTION]

--catalog CATALOG, -C CATALOG
Folder where is catalog file
--backup-id ID, -i ID
Backup-id of backup
--last, -L Last available backup
--user USER, -u USER Login name used to log into the remote host (where
you're restoring)
--last, -L Last available backup
--user USER, -u USER Login name used to log into the remote host (where
you're restoring)
--computer HOSTNAME, -c HOSTNAME
Hostname or ip address to perform restore
Hostname or ip address to perform restore
--type {Unix,Windows,MacOS}, -t {Unix,Windows,MacOS}
Type of operating system to perform restore
--timeout TIMEOUT, -T TIMEOUT
I/O timeout in seconds
--mirror, -m Mirror mode
--skip-error, -e Skip error.
--rsync-path, -R Select a custom rsync path.

.B config
.B config
[ACTION]

Init configuration:
--new, -n Generate new configuration
--remove, -r Remove exist configuration
--init INIT, -i INIT Reset catalog file. Specify path of backup folder.

Deploy configuration:
--deploy DEPLOY_HOST, -d DEPLOY_HOST
Deploy configuration to client: hostname or ip address
--user DEPLOY_USER, -u DEPLOY_USER
User of the remote machine

.B archive
.B archive
[ACTION]

--catalog CATALOG, -C CATALOG
Expand All @@ -122,8 +125,9 @@ Deploy configuration:
--timeout TIMEOUT, -T TIMEOUT
I/O timeout in seconds
--skip-error, -e Skip error
--rsync-path, -R Select a custom rsync path.

.B optional arguments
.B optional arguments
[OPTIONS]

-h, --help show help message and exit
Expand Down Expand Up @@ -168,6 +172,9 @@ Deploy configuration to machine:
Export a backup to another path:
O_O>$ bb export --catalog /mnt/backup/ --backup-id f0f700e8-0435-11e9-9e78-005056a664e0 --destination /mnt/export

Reset backup catalog:
O_O>$ bb config --init /mnt/backup/

.SH SEE ALSO
Full documentation is here:
https://butterfly-backup.readthedocs.io/en/latest/
Expand All @@ -176,4 +183,4 @@ No known bugs.
.SH AUTHOR
Matteo Guadrini <[email protected]>
.SH COPYRIGHT
(c) Matteo Guadrini. All rights reserved.
(c) Matteo Guadrini. All rights reserved.
47 changes: 43 additions & 4 deletions bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from utility import print_verbose

# region Global Variables
VERSION = '1.4.1'
VERSION = '1.5.0'


# endregion
Expand Down Expand Up @@ -252,7 +252,16 @@ def compose_command(flags, host):
"""
print_verbose(args.verbose, 'Build a rsync command')
# Set rsync binary
command = ['rsync']
if flags.rsync:
if os.path.exists(flags.rsync):
command = [flags.rsync]
else:
print(utility.PrintColor.YELLOW +
'WARNING: rsync binary {0} not exist! Set default.'.format(args.rsync)
+ utility.PrintColor.END)
command = ['rsync']
else:
command = ['rsync']
catalog = read_catalog(catalog_path)
if flags.action == 'backup':
# Set mode option
Expand Down Expand Up @@ -801,6 +810,20 @@ def check_configuration(ip):
return False


def init_catalog(catalog):
"""
:param catalog: catalog file
"""
config = read_catalog(catalog)
for cid in config.sections():
if not os.path.exists(config[cid]['path']):
print_verbose(args.verbose, "Backup-id {0} has been removed to catalog!".format(cid))
config.remove_section(cid)
# Write file
with open(catalog, 'w') as configfile:
config.write(configfile)


def parse_arguments():
"""
Function get arguments than specified in command line
Expand Down Expand Up @@ -828,6 +851,8 @@ def parse_arguments():
action='store_true')
group_config_mutually.add_argument('--remove', '-r', help='Remove exist configuration', dest='remove_conf',
action='store_true')
group_config_mutually.add_argument('--init', '-i', help='Reset catalog file. Specify path of backup folder.',
dest='init', action='store')
group_deploy = config.add_argument_group(title='Deploy configuration')
group_deploy_mutually = group_deploy.add_mutually_exclusive_group()
group_deploy_mutually.add_argument('--deploy', '-d', help='Deploy configuration to client: hostname or ip address',
Expand Down Expand Up @@ -864,6 +889,7 @@ def parse_arguments():
group_backup.add_argument('--timeout', '-T', help='I/O timeout in seconds', dest='timeout', action='store',
type=int)
group_backup.add_argument('--skip-error', '-e', help='Skip error', dest='skip_err', action='store_true')
group_backup.add_argument('--rsync-path', '-R', help='Custom rsync path', dest='rsync', action='store')
# restore session
restore = action.add_parser('restore', help='Restore options', parents=[parent_parser])
group_restore = restore.add_argument_group(title='Restore options')
Expand All @@ -883,6 +909,7 @@ def parse_arguments():
type=int)
group_restore.add_argument('--mirror', '-m', help='Mirror mode', dest='mirror', action='store_true')
group_restore.add_argument('--skip-error', '-e', help='Skip error', dest='skip_err', action='store_true')
group_restore.add_argument('--rsync-path', '-R', help='Custom rsync path', dest='rsync', action='store')
# archive session
archive = action.add_parser('archive', help='Archive options', parents=[parent_parser])
group_archive = archive.add_argument_group(title='Archive options')
Expand Down Expand Up @@ -924,6 +951,7 @@ def parse_arguments():
group_export.add_argument('--timeout', '-T', help='I/O timeout in seconds', dest='timeout', action='store',
type=int)
group_export.add_argument('--skip-error', '-e', help='Skip error', dest='skip_err', action='store_true')
group_export.add_argument('--rsync-path', '-R', help='Custom rsync path', dest='rsync', action='store')
# Return all args
parser_object.add_argument('--version', '-V', help='Print version', dest='version', action='store_true')
return parser_object
Expand All @@ -949,6 +977,9 @@ def parse_arguments():
remove_configuration()
elif args.deploy_host:
deploy_configuration(args.deploy_host, args.deploy_user)
elif args.init:
catalog_path = os.path.join(args.init, '.catalog.cfg')
init_catalog(catalog_path)
else:
parser.print_usage()
print('For ' + utility.PrintColor.BOLD + 'config' + utility.PrintColor.END + ' usage, "--help" or "-h"')
Expand Down Expand Up @@ -1305,8 +1336,16 @@ def parse_arguments():
logs = list()
logs.append(log_args)
# Set rsync binary and flags
expcmd = list()
expcmd.append('rsync')
if args.rsync:
if os.path.exists(args.rsync):
expcmd = [args.rsync]
else:
print(utility.PrintColor.YELLOW +
'WARNING: rsync binary {0} not exist! Set default.'.format(args.rsync)
+ utility.PrintColor.END)
expcmd = ['rsync']
else:
expcmd = ['rsync']
expcmd.append('-ah')
expcmd.append('--no-links')
# Check flags
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.
Loading

0 comments on commit 179a4ff

Please sign in to comment.