Skip to main content

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

uv is a fast Python package installer and resolver. To install the tool using uv:

$ uv pip install backup-to-dropbox

Or to install from source:

$ git clone https://github.com/salessandri/backup-to-dropbox.git
$ cd backup-to-dropbox
$ uv pip install .

Using pip

$ pip install backup-to-dropbox

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.

Development

This project uses pyproject.toml for package configuration and uv for dependency management. To set up a development environment:

$ uv venv
$ source .venv/bin/activate  # On Windows: .venv\Scripts\activate
$ uv pip install -e .

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

Metadata

Release files for backup-to-dropbox 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for backup-to-dropbox 0.4.0
File Size Uploaded
backup_to_dropbox-0.4.0.tar.gz 23.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for backup-to-dropbox 0.4.0
File Interpreter ABI Platform
backup_to_dropbox-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / backup_to_dropbox-0.4.0.tar.gz

Download URL backup_to_dropbox-0.4.0.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d02d0d99f4cebd9ab67e2437576aabea3d2a21011a86cf25a8e9a7b65139a8b7
BLAKE2b-256 checksum
How to use checksums
adf62b854c98c78c9a0d8f665ffc4651584067d22fd63f14e6d7a4f4204aaa41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / backup_to_dropbox-0.4.0-py3-none-any.whl

Download URL backup_to_dropbox-0.4.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d9f438d3222b856e2f2d09bfc682f4d89aecb8bda627855bcb2fccc799e8f87
BLAKE2b-256 checksum
How to use checksums
35f0b759045468a639e751eb41afd042e50121642cb6df19871c5a59676cd928
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page