Skip to content

Instantly share code, notes, and snippets.

@tiagoameller
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save tiagoameller/3e24e4c6047baeff38b8 to your computer and use it in GitHub Desktop.

Select an option

Save tiagoameller/3e24e4c6047baeff38b8 to your computer and use it in GitHub Desktop.
automatic backup for rails postgres database
#!/bin/bash
# Please see some environment variables must be declared outside this script
# To execute this script every six hours, put in your crontab -e
# m h dom mon dow command
# 0 */6 * * * /home/rails/pn_backup.sh
BackupHome=/home/rails/pn_backup/
BackupBase=`date +%Y-%m-%dT%H%M`
BackupFile="$BackupBase".sql
BackupZip="$BackupBase".tar.gz
cd $BackupHome
pg_dump pounou_production > $BackupFile
tar cvfz $BackupZip $BackupFile
rm $BackupFile
ftp -n -v $FTP_HOST << EOT
user $FTP_USER $FTP_PASSW
put $BackupZip
bye
EOT
cd -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment