This program provides three main functions:
- creates a compressed and encrypted backup of a specified directory
- schedules backups on a recurring basis for automated backup management using cron
- restores backups as needed
It keeps the latest backup of a particular folder, removing older backups to conserve storage space.
Why make this backup program?
I wanted a few different things:
- A backup program that would compress and encrypt things
- The freedom to select the compression and encryption algorithms
- The ability to experiment with the best compression and encryption algorithms
- To do all this in bash/shell (slightly works against exploring new algorithms, but I'm ok with that for now)
- Clone this repository to your local machine.
- Copy the
.env.example
file to.env
and set theENCRYPTION_KEY
environment variable to a random string - Save your encryption string somewhere where you won't lose it. You will need it to restore backups.
- Install
lrzip
(on mac osx:brew install lrzip
) - Run
./backup.sh
to see detailed usage notes.
The other dependencies (zip
and openssl
are included by default on a mac).
Reference:
backup -d [/path/to/files] -o [/where/to/put/backup] -h [hour to repeat] [-l size limit]
# a one time backup:
backup -d /Users/bae/Documents -o /Volumes/bae-back-that-up/
# a backup scheduled to re-occur at the 22nd hour of the day:
backup -d /Users/bae/Documents -o /Volumes/bae-back-that-up/ -h 22
# a backup that also filters out files larger than 100k
backup -d /Users/bae/Documents -o /Volumes/bae-back-that-up/ -h 22 -l 100k
This command will create an encrypted backup named:
users_bae_documents.zip.lrz.enc.<8 hex>
in /Volumes/bae-back-that-up/
.
- -d: The directory to backup (required).
- -o: The output location. The file will be named automatically (required).
- -h: An optional hour of the day (0-23) to schedule the backup to run (optional).
- -l: Limits the size of files that will be included in the backup (optional).
The restore.sh script decrypts and decompresses a backup file.
./restore.sh -f /path/to/files.zip.lrz.enc.12345678 -o /where/to/put/decrypted-backup
This command will take /path/to/files.zip.lrz.enc.12345678
, decrypt it using the ENCRYPTION_KEY environment variable, and lrzip
decompress it to /where/to/put/decrypted-backup/files.zip
. The original encrypted file is retained in case of problems with the ENCRYPTION KEY. The zip file is left un-expanded, allowing the user to relocate it as needed.
- -f: The file to decrypt and decompress (required).
- -o: The output directory. The filename is restored with the original filename (required).
Contributions are welcome!
The issues tab has enhancement ideas and bugs. Please use that to raise any new issues, or to look for ideas on ways to contribute.
For PRs, please include:
- the problem you're solving, as well as a link to the issue it resolves
- an explanation of your implementation
- details of how you tested your solution