Saturday, 7 January 2017

Dokumentasi : Backup & Restore

Status : Draft

Disini kita ingin melakukan backup database dan folder upload setiap hari pada pukul 12 siang. 

Buat script backup di ~/bin/backup.sh

#!/bin/bash

hari=$(date +"%A")

pg_dump --file "/backup/banksoal/postgresql/$hari.sql" --host "localhost" --username="banksoal" -w --verbose --role "banksoal" --format=c --blobs "banksoal"

mkdir -p /backup/banksoal/webapps/upload/$hari

rsync -zavh /opt/www/banksoal/application/webroot/upload /backup/banksoal/webapps/upload/$hari

Buat entri cron :

$crontab  -e

# m h  dom mon dow   command
* 12 * * 1 /home/openthinklabs/bin/backup.sh
* 12 * * 2 /home/openthinklabs/bin/backup.sh
* 12 * * 3 /home/openthinklabs/bin/backup.sh
* 12 * * 4 /home/openthinklabs/bin/backup.sh
* 12 * * 5 /home/openthinklabs/bin/backup.sh
* 12 * * 6 /home/openthinklabs/bin/backup.sh

.pgpass


nano ~/.pgpass
localhost:5432:banksoal:banksoal:password

Format :

hostname:port:database:username:password

sudo chmod 600 ~/.pgpass
sudo chown user.postgres ~/.pgpass 

No comments:

Post a Comment