5.1. Backup and Restore
Files to consider:
Code versions using Git and uploaded to Bitbucket.
Requirements.txt created
Postgresql DB dump (not covered by Git)
Copy of settings in local.py because it is not covered by Git
Copy of database settings/password from the main server (probably in local.py)
Any user uploaded files
Conf files - Gunicorn, Nginx and Supervisor
SSL private key and ssl-bundle and ssl confirmation of ownership file
Note
Backup using both dumpdata and pg_dump
5.1.1. Backup
Follow the Backup instructions for pg_dump to create an SQL backup of the database then copy it to the new virtualenv.
Follow the Dumpdata instructions to create a Django JSON backup of the database then copy it to the new virtualenv.
Ensure you also have a copy of local.py plus any other configuration files.
Copy the media file but do not worry about the static file. You can use Rsync for this.
5.1.2. Restore
Set up the project:
Git
Config files
local.py
Backup dumps
Media files
Postgres database
Run migrations
Follow the Django Loaddata instructions to restore the database.
5.1.3. Rsync
Commands for local to connected drive:
rsync -avzh /home/username/folder /mnt/carly/username/backup/
rsync -avzh --stats --progress SERVER:PATH/TO/FILE LOCAL/PATH/TO/FILE
Note
The source is the folder name with no forward slash. The destination is the root folder where it will go, not the name of folder being synchronised.
Note
It’s a one way sync i.e. will not remove files from the backup that have been deleted in the source unless you add –delete
rsync -avzh /home/username/folder /mnt/carly/username/backup/ --delete
Commands for copying from a server to the local machine for backing up:
rsync -avzh --stats --progress SERVER:REMOTE_PATH/FOLDER/ /LOCAL_PATH/FOLDER/
5.1.4. Fabric
Fabric can be used with a fabfile to automate the backup process.