Skip to content

Commit

Permalink
Merge 5c4ec6e into 3f16a50
Browse files Browse the repository at this point in the history
  • Loading branch information
clvz committed Aug 20, 2018
2 parents 3f16a50 + 5c4ec6e commit 2acd8dc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
26 changes: 21 additions & 5 deletions rsync_system_backup/__init__.py
Expand Up @@ -178,6 +178,11 @@ def dry_run(self):
""":data:`True` to simulate the backup without writing any files, :data:`False` otherwise."""
return False

@mutable_property
def multi_fs(self):
""":data:`True` to allow rsync to cross filesystem boundaries, :data:`False` otherwise."""
return False

@lazy_property(writable=True)
def exclude_list(self):
"""
Expand Down Expand Up @@ -288,6 +293,16 @@ def sudo_enabled(self):
""":data:`True` to run ``rsync`` and snapshot creation with superuser privileges, :data:`False` otherwise."""
return True

@mutable_property
def rsync_verbose_count(self):
""":data: defaults to zero. Represents the number of -V arguments received"""
return 0

@mutable_property
def rsync_quiet_count(self):
""":data: defaults to zero. Represents the number of -Q arguments received"""
return 0

def execute(self):
"""
Execute the requested actions (backup, snapshot and/or rotate).
Expand Down Expand Up @@ -514,6 +529,10 @@ def transfer_changes(self):
if self.dry_run:
rsync_command.append('--dry-run')
rsync_command.append('--verbose')
for _ in range(self.rsync_verbose_count):
rsync_command.append('--verbose')
for _ in range(self.rsync_quiet_count):
rsync_command.append('--quiet')
# The following rsync options delete files in the backup
# destination that no longer exist on the local system.
# Due to snapshotting this won't cause data loss.
Expand All @@ -528,11 +547,8 @@ def transfer_changes(self):
rsync_command.append('--xattrs')
# The following rsync option avoids including mounted external
# drives like USB sticks in system backups.
#
# FIXME This will most likely be problematic for users with fancy
# partitioning schemes that e.g. mount /home to a different
# disk or partition.
rsync_command.append('--one-file-system')
if not self.multi_fs:
rsync_command.append('--one-file-system')
# The following rsync options exclude irrelevant directories (to my
# subjective mind) from the system backup.
for pattern in self.excluded_roots:
Expand Down
34 changes: 30 additions & 4 deletions rsync_system_backup/cli.py
Expand Up @@ -124,6 +124,11 @@
create a backup or snapshot but it does run rsync with the --dry-run
option.
--multi-fs
Allow rsync to cross filesystem boundaries. (has the opposite effect
of rsync option "-x, --one-file-system").
-x, --exclude=PATTERN
Selectively exclude certain files from being included in the backup.
Expand All @@ -145,11 +150,19 @@
-v, --verbose
Make more noise (increase logging verbosity). Can be repeated.
Make more noise (increase logging verbosity for the python app). Can be repeated.
-V, --rsync-verbose
Make the rsync program more noisy. Can be repeated.
-q, --quiet
Make less noise (decrease logging verbosity). Can be repeated.
Make less noise (decrease logging verbosity for the python app). Can be repeated.
-Q, --rsync-quiet
Make the rsync program less noisy.
-h, --help
Expand Down Expand Up @@ -194,10 +207,11 @@ def main():
program_opts = dict()
dest_opts = dict()
try:
options, arguments = getopt.gnu_getopt(sys.argv[1:], 'bsrm:c:t:i:unx:fvqh', [
options, arguments = getopt.gnu_getopt(sys.argv[1:], 'bsrm:c:t:i:unx:fvqhVQ', [
'backup', 'snapshot', 'rotate', 'mount=', 'crypto=', 'tunnel=',
'ionice=', 'no-sudo', 'dry-run', 'exclude=', 'force',
'disable-notifications', 'verbose', 'quiet', 'help',
'disable-notifications', 'verbose', 'quiet', 'help', 'multi-fs',
'rsync-verbose', 'rsync-quiet',
])
for option, value in options:
if option in ('-b', '--backup'):
Expand Down Expand Up @@ -237,8 +251,20 @@ def main():
elif option in ('-x', '--exclude'):
program_opts.setdefault('exclude_list', [])
program_opts['exclude_list'].append(value)
elif option == '--multi-fs':
program_opts['multi_fs'] = True
elif option == '--disable-notifications':
program_opts['notifications_enabled'] = False
elif option in ('-V', '--rsync-verbose'):
if 'rsync_verbose_count' not in program_opts:
program_opts['rsync_verbose_count'] = 1
else:
program_opts['rsync_verbose_count'] = program_opts['rsync_verbose_count'] + 1
elif option in ('-Q', '--rsync-quiet'):
if 'rsync_quiet_count' not in program_opts:
program_opts['rsync_quiet_count'] = 1
else:
program_opts['rsync_quiet_count'] = program_opts['rsync_quiet_count'] + 1
elif option in ('-v', '--verbose'):
coloredlogs.increase_verbosity()
elif option in ('-q', '--quiet'):
Expand Down

0 comments on commit 2acd8dc

Please sign in to comment.