Backup shell script for my Rails applications

written by mikhailov on August 11th, 2009 @ 05:27 AM

Howia lads,
Today I'd like to show you the optimal backup shell script for all of my Rails Applications. Nobody love to setup the backup workflow, but all want to sleep well and have their data duplicated somewhere like Amazon S3 :) Here the script who take care of yours backup process

# Take care about folders structure for the usual script workflow:
# /home/demo/backup/
# /home/demo/backup/redmine_folder/
# /home/demo/backup/redmine_folder/script.sh - the following script should be landing here
# /home/demo/backup/redmine_folder/files
# /home/demo/public_html/
# /home/demo/public_html/redmine_folder
#
# crontab -e -u demo
# 0 20 * * * /home/demo/backup/redmine_folder/script.sh


# ---BACKUP SCRIPT---

#!/bin/sh
folder=redmine_folder
db=redmine_production

# Change directory and remove files older than 30days
cd ~/backup/$folder/files
find . -mtime +30 |xargs rm

# Database
file01=$folder.db_$(date +"%Y_%m_%d_%H-%M")
mysqldump -u user_name -pmy_sycret_password --single-transaction $db | gzip -c > $file01.gz

# App
file02=$folder.app_$(date +"%Y_%m_%d_%H-%M")
tar czf ~/backup/$folder/files/$file02.tgz ~/public_html/$folder > /dev/null

# S3 sync
ruby ~/backup/s3sync/s3cmd.rb put s3bucket:backup/$folder/db/$file01.gz $file01.gz
ruby ~/backup/s3sync/s3cmd.rb put s3bucket:backup/$folder/app/$file02.tgz $file02.tgz

# ---BACKUP SCRIPT---

S3Sync

http://pastie.org/579582

Comments

  • Glenn Gillen on 11 Aug 13:00

    I've been working on a similar script/gem. Still very much beta (in that it works, but not complete enough for my to publicly support it) but it will handle encryption, compression, and storing on S3:

    http://github.com/rubypond/s3backup-manager/

    I'm building in adapters for various databases, postgres is almost complete.

    Glenn

  • David Paluy on 12 Aug 10:03

    You should check the following gem from Astrails: Safe - simple backup for mysql, posgresql, svn and files to s3 or local filesystem

    http://github.com/astrails/safe/tree/master

Comments are closed

Custom Search