Skip to main content

Duplicity backup to S3 for production servers using simple yaml config file.

Project description

Duplicity Backup to S3

image

image

image

Duplicity backup to S3 for production servers using simple yaml file.

License

Free software: Apache Software License 2.0

Features

This is a duplicity command line backup wrapper that will backup to S3 that is using a validated yaml configuration file using modern and awesome CLI patterns. The commands incremental, list files, status, verify, cleanup, remove and init are implemented.

The primary use case to build this (yet another one) CLI wrapper for duplicity, is to be able to deploy the command in production and inject it into a cron.daily and having a hands-off automated backup of production servers. We use it a KE-works to automate our production server backups to Amazon S3.

OS Dependencies

Installation

You can either install this as a system command on any operating system supporting Python 3.5 or later.

To install as global command from PyPI:

sudo python3 -m pip install duplicity-backup-s3

To install for your user only from PyPI enter the following commmand:

python3 -m pip install --user duplicity-backup-s3

To install from the git repository (latest master branch):

python3 -m pip install --user git+https://github.com/jberends/duplicity_backup.git#wheel=duplicity_backup_s3

First use

To first use, you need to create a configuration yaml file. You can use the helper command init for that. Use the built-in help function for your enjoyment.

# help is neigh
duplicity_backup_s3 --help

# and to init the configuration YAML file
duplicity_backup_s3 init

It will drop you a duplicity_backup_s3.yaml in your current directory. That may look like this:

aws:
  AWS_ACCESS_KEY_ID: foobar_aws_key_id  # your amazon S3 user that has write right to a backup bucket
  AWS_SECRET_ACCESS_KEY: foobar_aws_access_key  # your amazon S3 user secret
backuproot: /home  # the backup 'root' path. Everything underneath is considered for backup.
excludes:
  - "**"  # a list of exclude paths. May be '**' to exclude everything except what you include
includes:
  - /home/Pictures  # a list of includes, which are full paths
  - /home/Music
remote:
  bucket: '<an_s3_bucket>'  # S3 bucket name
  path: '__test'  # subpath within the bucket
full_if_older_than: 7D  # default is incremental, will create full backup every 7Days.

You can alter the configuration file to your liking. The command will check the configuration for its validity and tell you what went wrong and what you need to correct. If you made mistakes, it can be beneficial to checkout the duplicity man page for more information on that topic. However we tried to be as verbose as possible to guide you in the right direction.

First backup

To perform your first backup, which is a full one, use the following command:

duplicity_backup_s3 incr --verbose

# or if the config is somewhere else
duplicity_backup_s3 incr --config /path/to/configuation.yaml

That might take time according to the size of the backup. You can see the volumes being uploaded to your configured S3 bucket using the S3 console.

To check the backup collection, list and verify the contents of the backup you may use:

# collection status
duplicity_backup_s3 status

# list all files
duplicity_backup_s3 list

# verify backup
duplicity_backup_s3 verify

Remove old backups

To remove older backups, duplicity provides some commands. We implemented those in the remove command.

# to remove backups older than 7D
duplicity_backup_s3 remove --older-than 7D

# to remove older backup except the last 4 full backups
duplicity_backup_s3 remove --all-but-n-full 4

Restore backups

To restore backup we implemented the restore command.

# to restore backups from yesterday to a current directory
duplicity_backup_s3 restore --time 1D

# to restore specific subdirectory from a specific date/time to a custom directory
duplicity_backup_s3 restore --dir specific_subdir \
    --time 2020-12-08T22:22:00+01:00 --target ~/a_restoredir

Using this as daily backup in a cronjob

To use this in a daily cron job, you can alter the crontab for the user root

crontab -u root -e

You can alter the crontab in the following way

# Daily backup and remove older backup
7 4 * * * /bin/duplicity_backup_s3 incr --config=/path/to/conf.yaml && /bin/duplicity_backup_s3 remove --older-than 7D --config=/path/to/conf.yaml
# | | | | +- the command to execute
# | | | +--- day of the week (0-6) Sunday=0 (*=every day)
# | | +----- month of the year (*=every month)
# | +------- day of the month (*=every day)
# +--------- hour of the day
#----------- minute in the hour

TODO

  • implement appdirs for default configuration file placement
  • implement restore for restoring
  • test on digitalocean
  • If requested migrate --s3-european-buckets to configuration file
  • If requested implement GPG/Encryption capabilities. Possibly reusing code of kecpkg-tools to manage certificates.
  • Initialise itself into cron.daily

Credits

  • This package was inspired by the great work done by the duplicity team, back in the days.
  • This package was inspired by the great amount of bash code by the duplicity_backup.sh project.
  • This package is thankful on my knees to the great work done by the Authors and contributors behind the Click project, packing tons of CLI awesomeness since 2014.
  • This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template. \n\n# Changelog

v1.1.0 (8DEC20)

  • added restore command implementation.

v1.0.2 (3APR20)

  • Added appdirs to the setup.py requirements.

v1.0.1 (UNRELEASED)

Not released to the public.

v1.0.0 (16DEC19)

First production release.

  • implemented appdirs, such that the configuration file can be safely placed and located from a known configuration directory on disk.
  • added remove command to remove collections from the backup target after a specified time. Please consult the duplicity_backup_s3 remove --help documentation for guidance.
  • added init command to initialise the configuration in an interactive fashion for users.
  • various development improvements, eg Github actions for testing and publishing to PyPI; removed all flake8 warnings and pydocstyle errors. Added pre-commit hooks. Code is A++ grade now.

v0.5.0 (5JUN19)

First initial public release.

  • commands incr, list, status, verify, cleanup implemented.
  • added yaml schema check for the configuration file.

v0.2.0 (3JUN19)

Internal release.

  • migrated to command structure. Now offers incr and init

v0.1.0 (3JUN19)

Internal release.

  • First release on PyPI.

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

duplicity_backup_s3-1.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

duplicity_backup_s3-1.1.0-py2.py3-none-any.whl (22.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file duplicity_backup_s3-1.1.0.tar.gz.

File metadata

  • Download URL: duplicity_backup_s3-1.1.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for duplicity_backup_s3-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e2cc6de1ff856c03356563ab1b7116a703e9e0bb3992b95e44508a8122b8b6a6
MD5 69c842578a17a235c15bdf19f3872ae3
BLAKE2b-256 329528edb51ec0634152c498df51e7e1a7f44f3a8bdd431f770f77030cdca8e8

See more details on using hashes here.

Provenance

File details

Details for the file duplicity_backup_s3-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: duplicity_backup_s3-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for duplicity_backup_s3-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2b7e919420afd761e252a21b644ddb00187938b22a058d1e37ab19a16492501b
MD5 fe1dc293dae9911240ae88c45ef23303
BLAKE2b-256 ead9d3eda9ba7afa3eb9a4537f6d28698734359409d266a03faba840c05eb62e

See more details on using hashes here.

Provenance

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