From 970d3dde1efdb1f0add4ed98d5fe26f9b56217e9 Mon Sep 17 00:00:00 2001 From: Fuxino Date: Thu, 15 Jun 2023 21:30:43 +0200 Subject: [PATCH] Add manual selection of rsync options --- man/simple_backup.1 | 19 +++++++++++++++++++ simple_backup/__init__.py | 2 +- simple_backup/simple_backup.py | 20 ++++++++++++++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/man/simple_backup.1 b/man/simple_backup.1 index c68f70b..f45db44 100644 --- a/man/simple_backup.1 +++ b/man/simple_backup.1 @@ -59,6 +59,25 @@ Default behavior is to remove old backups after successfully completing the back .TP .B \-\-no\-syslog Don't use systemd journal for logging +.TP +.B \-\-rsync\-options OPTIONS [OPTION...] +By default, the following rsync options are used: +.RS +.PP +\-a \-r \-c \-v \-h \-H \-X +.PP +Using \-\-rsync\-options it is possible to manually select which options to use. Supported values are the following: +.PP +\-a, \-l, \-p, \-t, \-g, \-o, \-c, \-h, \-D, \-H, \-X +.PP +Options \-r and \-v are used in any case. Not that options must be specified without dash (\-), for example: +.PP +.EX +simple_backup \-\-rsync\-options a l p +.EE +.TP +Check rsync(1) for details about the options. +.RE .SH CONFIGURATION An example configuration file is provided at \(aq/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location ($HOME/.config/simple_backup) and edit it as needed. diff --git a/simple_backup/__init__.py b/simple_backup/__init__.py index 773d4e5..0b093c1 100644 --- a/simple_backup/__init__.py +++ b/simple_backup/__init__.py @@ -1,3 +1,3 @@ """Init.""" -__version__ = '3.4.1' +__version__ = '3.5.0' diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index 583e535..980bf59 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -283,6 +283,9 @@ def _parse_arguments(): parser.add_argument('--remove-before-backup', action='store_true', help='Remove old backups before executing the backup, instead of after') parser.add_argument('--no-syslog', action='store_true', help='Disable systemd journal logging') + parser.add_argument('--rsync-options', nargs='+', + choices=['a', 'l', 'p', 't', 'g', 'o', 'c', 'h', 'D', 'H', 'X'], + help='Specify options for rsync') args = parser.parse_args() @@ -369,12 +372,21 @@ def simple_backup(): if args.keep is not None: keep = args.keep - if args.checksum: - backup_options = '-arcvh -H -X' + if args.rsync_options is None: + if args.checksum: + rsync_options = '-arcvh -H -X' + else: + rsync_options = '-arvh -H -X' else: - backup_options = '-arvh -H -X' + rsync_options = '-r -v ' - backup = Backup(inputs, output, exclude, keep, backup_options, remove_before=args.remove_before_backup) + for ro in args.rsync_options: + rsync_options = rsync_options + f'-{ro} ' + + if '-c ' not in rsync_options and args.checksum: + rsync_options = rsync_options + '-c' + + backup = Backup(inputs, output, exclude, keep, rsync_options, remove_before=args.remove_before_backup) return_code = backup.check_params()