Auto backups setup (DB)

From Origami_Wiki
Jump to navigation Jump to search

This page explains the steps to be carried out once a new application is setup and it's database needs to be backed up daily.


1. Put the backup script in the live server depending on whether it's a postgres or mysql db and add a cron to run it daily.
Example script:

current_time=$(date "+%d-%m-%Y_%H:%M");
pg_dump -U ddugky_dbuser -h localhost -Ft ddugky_db2 -n public -x -O -f "mis.ddugky.co.in/databasebackup/ddugkymis_$current_time"."tar";


2. Now, creata a ftp user whose home directory is the backup folder.


3. Now, we need to create a script in our local system to download this backup file automatically.
To do that,
Create a new shell script file (say, appname_db.sh) inside /home/origami/backupscripts/ folder
Example content,

#!/bin/bash

HOST='107.161.191.186' #IP Address of the remote server
USER='dbbmis@mis.ddugky.co.in' #Username of ftp
PASSWORD='WvloVGFK3BMys' #Password of ftp
REMOTEFILENAME="ddugkymis_$(date +%d-%m-%Y)_*" #File name of backup file in server ddugkymis_01-01-2018_00:00.tar
LOCALDIR="Ddugky"

. downloadfile.sh


4. Now add the new above created file to the list of applications that are backed up daily. To do that,
Open downloadfile.sh in the same folder and add ". appname_db.sh" without quotes, to the last line. Save the file.


The backup will be downloaded automatically from the next day, once the cron runs.


Note: make sure the backup file name format in the remote server and the script in local machine are same, otherwise the script will fail to find the file in the remote server.