Skip to content

3 CentOS 7 Backup and restore proceedure

bartmika edited this page Apr 25, 2019 · 1 revision

CentOS 7 Backup and Restore

The goal of this article is to help setup the various backup / restore solutions for this project.

Manual Backup / Restore Procedure

CentOS 7 QA / Production

While you are on the CentOS 7 server, please login as the administrator and then run the following in your console:

  1. Go inside postgres.
su - postgres
  1. Export out database.
pg_dump -U postgres -d academicstoday_db > academicstoday_db.backup
  1. Exit postgres.
exit
  1. Move our export to our django user.
mv /var/lib/pgsql/academicstoday_db.backup /home/techops/academicstoday_db.backup
  1. Delegate authority for the administrator to manage the exported database.
chown techops /home/techops/academicstoday_db.backup;
chgrp techops /home/techops/academicstoday_db.backup;
  1. Log in as the administrator and confirm the database export was successful.
su - techops
cd ~/
ls -alh
  1. Congradulations you've exported a copy of the database.

Developer Localhost

Download Database

The following instructions will work Linux or MacOS.

  1. Download the database (Mac/Linux)
scp -i ~/.ssh/id_rsa techops@academicstoday.ca:/home/techops/academicstoday_db.backup /var/tmp
  1. Congradulations you've saved a copy of the database onto your local machine.

  2. Confirm your copy.

ls -alh /var/tmp

Restore Database (MacOS)

  1. Load up the postgres app (we are assuming you are running Postgres.app) and run the following. Please ensure you do not run the drop command in your production environment!
drop database academicstoday_db;
create database academicstoday_db;
  1. Open Terminal and run the following:
psql -U django academicstoday_db < /var/tmp/academicstoday_db.backup;
  1. 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