.. _backup_and_restore: ================== 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`` Backup ====== Follow the :ref:`postgresql_backup` instructions for ``pg_dump`` to create an SQL backup of the database then copy it to the new virtualenv. Follow the :ref:`django_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 :ref:`rsync` for this. Restore ======= Set up the project:: Git Config files local.py Backup dumps Media files Postgres database Run migrations Follow the Django :ref:`django_loaddata` instructions to restore the database. .. _rsync: 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/ Fabric ====== Fabric can be used with a fabfile to automate the backup process.