Skip to main content

Automate execution of various rsync commands based on profiles defined on a YAML configuration file

Project description

Auto rsync

Command to automate execution of various rsync commands based on profiles defined on a YAML configuration file.

  • Instead of doing:

    rsync -avySH --delete --backup --backup-dir=../deleted/$timestamp/ "/media/Media/Photos" "user@host.com:/media/backup/filesets/$hostname.photos"
    

    Just do:

    autorsync -p photos
    
  • Instead of doing:

    rsync -avySH --delete --backup --backup-dir=../deleted/$timestamp/ "/media/Media/Photos" "user@host.com:/media/backup/filesets/$hostname.photos"
    rsync -avySH --delete --backup --backup-dir=../deleted/$timestamp/ "/media/Media/Books" "user@host.com:/media/backup/filesets/$hostname.books"
    rsync -avySH --delete --backup --backup-dir=../deleted/$timestamp/ "/media/Media/Music" "user@host.com:/media/backup/filesets/$hostname.music"
    

    Just do:

    autorsync
    

Or, in more general terms, instead of doing long rsync commands for your everyday backups, or putting them in adhoc scripts, write the clear ~/autorsync.yaml file and let autorsync to the work for you.

Installation

pip3 install auto-remote-sync --user

(Sorry for the long package name, ideally this would be simply autorsync, but name autosync was already taken and PyPi would not allow similar names).

Check PyPi and GitHub for autorsync.

Usage

Organize Profiles in ~/autorsync.yaml

Here is an example with some defaults and a few profiles:

DEFAULTS:
    source_part1: '{{home}}/Media'
    target_part1: user@remote.host.com:/media/backup/filesets
    delete: True
    backup: True
    backup_dir: ../deleted/{{time.strftime('%Y.%m.%d-%H.%M.%S')}}/
    background: False

profiles:
    - name: books
      source_part2: Books/
      target_part2: '{{hostname}}.books/files'
      background: True

    - name: nextcloud.data
      source: /var/lib/nextcloud/data
      target_part2: '{{hostname}}.nextcloud_files'
      extra: --copy-links --no-atimes --itemize-changes

Notes about this configuration

  • All profiles inherit parameters from DEFAULTS. If parameter isn’t set in the profile, the value defined in DEFAULTS will be used.
  • For each profile, the Source is defined by source parameter, or, if not defined, by source_part1/source_part2
  • Target follows same logic: target or target_part1/target_part2
  • delete makes rsync delete files in target that are absent in source
  • backup and backup_dir makes rsync save backups on target of deleted or modified files on source. Value on backup_dir is a path relative to target folder
  • extra lets you add extra rsync switches and can be used in the DEFAULTS section (to affect all profiles) or just into a specific profile.
  • You can use Jinja logic in path parts, surrounded by {{}}. Currently these are the available variables:
    • time, a Python datetime.datetime object which includes local timezone
    • hostname, such as “rocket”
    • Hostname, such as “rocket.mydomain.com” (FQDN)
    • username, UNIX user name as “joanbaez”
    • home, user’s home folder as “/home/joanbaez”
    • userid, user ID as “504”
    • gecos, user long name as “Joan Baez”

Example usage

  • Show all profiles:

    autorsync -l
    
  • Run rsync for all profiles:

    autorsync
    
  • Run rsync only for profile books

    autorsync -p books
    
  • Simulate rsync only for profile books (force rsync’s --dry-run)

    autorsync -n -p books
    

    or

    autorsync --dry-run -p books
    
  • Run rsync for 2 profiles from a non-default configuration file:

    autorsync -c /etc/autorsync.yaml -p "books, photos"
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_remote_sync-1.0.9.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

auto_remote_sync-1.0.9-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file auto_remote_sync-1.0.9.tar.gz.

File metadata

  • Download URL: auto_remote_sync-1.0.9.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for auto_remote_sync-1.0.9.tar.gz
Algorithm Hash digest
SHA256 27fdf1eefd466ae0b0ccbceb6cfd8da401868ea043ce954f1cc2e141a1e6a038
MD5 1889ff966b8aba0ef93f614016bb3d0f
BLAKE2b-256 62b4777727b2d930191421b07291421b25a1835dc470e5dbd4c8cdac49e18c0d

See more details on using hashes here.

File details

Details for the file auto_remote_sync-1.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for auto_remote_sync-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e9e926d49c1af5734900255995fe8a05f3bd445cb9512b9af89dea7cfd7bb307
MD5 b150bd73fb822397615f4d4fc732db4a
BLAKE2b-256 745ec2fe58aec72a09ccbbf2c72acf81a3a43160a11b6ded94860f2e46988407

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page