Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Tool to generate backups (tar.gz files) and upload them to Dropbox

Project description

Backup To Dropbox

This is a small utility written in python3 that allows generating tar-gzipped backups and upload them to a Dropbox account.

Installing

Using pip:

$ pip install backup-to-dropbox

Or manually running within the project's root folder:

$ python3 setup.py install

Dependencies

The only requirements for this tool are: python3 (>= 3.6) and dropbox (>= 10). Optionally, if you want to encrypt the backups using GPG the pretty-bad-protocol is needed too.

Usage

Obtaining an API Key

In order to use this tool a Dropbox API token is needed. To obtain one, an app needs to be created and an OAuth2 token generated for it. All this can be done with a few clicks thorough Dropbox's web interface. In this link you can find a step-by-step guide.

IMPORTANT NOTE: I strongly suggest that you only give permissions to the app to access a single folder. This minimizes the risk of exposing the whole account in case the token gets stolen but also means that all the backups are going to be neatly stored and tucked away in a separate folder.

Generating a backup

In order to generate a backup the application takes two required arguments: the backup's name and the list of paths to back up.

The name is used to create a subfolder under the Dropbox's root (or the application's folder root) where all the backups with the same name are going to be stored.

A tar-gzipped file is going to be created with each one of the paths that are given which actually exist. Both, full and relative paths can be used and they will be added to the tar-gzipped as given.

The file is going to be uploaded with the name yyyy-mm-dd-HHMM.tar.gz at the time of the execution if the file already exists, the backup will fail.

Keeping a max number of backups

One of the features included is the ability to only keep a certain number of backups. This is done by passing the flag --max-backups to the program followed by the number of backups to keep.

The application will delete the oldest files in the given backup name folder until the count is the argument passed minus one. This is done so as to leave space for the backup being currently generated.

Encrypting the backup

Currently, it is supported to encrypt the generated backup using GPG targeting a particular key. In order to use this, the public key needs to be already located in a gpg compatible keyring in the host.

The following arguments are used to enable the encryption:

  • --gpg-encrypt <KEY_FINGERPRINT>: This enables the encryption and sets the key to use for encryption.
  • --gpg-home <GNUPG_HOME> (optional, default: platform dependent): If set, it uses the path given as the gnupg home folder.
  • --gpg-pubkeyring <PUBKEYRING_FILE> (optional, default: pubring.gpg): If set, it uses the file given as the public key-ring.

When encrypting the backup the filename generated will have the .enc extension.

To decipher the backup, in a host where the secret key is located run:

$ cat 2020-05-01-2300.tar.gz.enc | gpg --decrypt > 2020-05-01-2300.tar.gz

Example

$ ./backup-to-dropbox.py --api-key <api-key> --backup-name myserver1-logs --max-backups 10 /var/log/

Generates a backup of the /var/log folder and uploads it under [Apps/theappyouregistered]/myserver1-logs/yyyy-mm-dd-HHMM.tar.gz. Only the last 10 backups are kept.

Details

If the backup is not larger than 150MB, a single request is used to upload the file. In case the file to upload is larger, a multi-request session where each request will upload a 150MB chunk. Uploading a file larger than 350GB is not possible, this is a Dropbox limitation.

License

MIT

Project details


Download files

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

Files for backup-to-dropbox, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size backup_to_dropbox-0.2.0-py3-none-any.whl (10.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size backup-to-dropbox-0.2.0.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page