3 CentOS 7 Backup and restore proceedure - AcademicsToday/academicstoday-django GitHub Wiki
The goal of this article is to help setup the various backup / restore solutions for this project.
While you are on the CentOS 7 server, please login as the administrator and then run the following in your console:
- Go inside postgres.
su - postgres
- Export out database.
pg_dump -U postgres -d academicstoday_db > academicstoday_db.backup
- Exit postgres.
exit
- Move our export to our
djangouser.
mv /var/lib/pgsql/academicstoday_db.backup /home/techops/academicstoday_db.backup
- Delegate authority for the administrator to manage the exported database.
chown techops /home/techops/academicstoday_db.backup;
chgrp techops /home/techops/academicstoday_db.backup;
- Log in as the administrator and confirm the database export was successful.
su - techops
cd ~/
ls -alh
- Congradulations you've exported a copy of the database.
The following instructions will work Linux or MacOS.
- Download the database (Mac/Linux)
scp -i ~/.ssh/id_rsa [email protected]:/home/techops/academicstoday_db.backup /var/tmp
-
Congradulations you've saved a copy of the database onto your local machine.
-
Confirm your copy.
ls -alh /var/tmp
- Load up the
postgresapp (we are assuming you are running Postgres.app) and run the following. Please ensure you do not run thedropcommand in your production environment!
drop database academicstoday_db;
create database academicstoday_db;
- Open
Terminaland run the following:
psql -U django academicstoday_db < /var/tmp/academicstoday_db.backup;
- Congradulations you've restored the production environment data onto your local machine. Now before you run your application, please run the following backfill command.
(env)$ python manage.py backfill