Tutorial: Basic website and database backups with Duplicity
This tutorial will show you how you can back up your website and database with Duplicity. Duplicity is a very useful tool to make remote unassisted backups. The backups can be incremental, encrypted, and over a variety of transports.
There are a few steps involved in the process of setting this up, and also a few preconditions:
- The tutorial works best with a VPS, were you have full root access to the filesystem and database
- The tutorial is targeted at debian/ubuntu, but with adaption of commands will work under CentOS/RHEL.
- You need an off-site location to store the backups (other vps for example)
Basic web application backup
First I'll try to educate you a little bit with some theory.
This tutorial works for all web applications, since they almost all share the same common structure:
- source code (.php files, .js files (node), .rb files (rails) etc.)
- database (MySQL, PostgreSQL, MongoDB etc.)
- configuration (apache config, nginx config, mysql config, application config)
We are going to back up files. Two of the three things above are already files, and the database will be exported to a file. The database will be exported so that it can be imported again using native tools (mysqldump, mongodump etc.), since just copying the database folders and files will almost always result in a corrupted database.
Duplicity has a few advantages to other backup tools and scripts:
- Incremental backups (Saving size)
- A lot of storage options (ssh, rsync, ftp, amazon S3, IMAP, google drive and more.)
- Encryption built in
- Easy to set up and maintain.
I myself have the following set up for almost all of my web application backups:
- Shell script to export the databases
- Duplicity backing up the files to a "storage" VPS
- The storage vps is just a server with a lot of HDD space doing nothing else.
- Some apps back up daily, some hourly and some weekly.