Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Complete backup of all domains to strongspace

#!/usr/local/bin/bash
# 
# comprehensive TextDrive backup to Strongspace
# Joel Dueck (http://jdueck.net)
#
# This script will backup all websites in your TextDrive account to Strongspace.
#
#         1. Save this script into your home dir,  chmod it to 700 for security
# 2. Create a pair of ssh keys; install the public key on your strongspace account and the private one in ~/.ssh
# 3. Change the configuration variables below

## Configuration section
#  [Don't forget trailing slashes for all directories!]

        MYSQL_USERNAME=name
        MYSQL_PW=password

        # Optional: Enter the path in your TextDrive account where your database backups are stored.
        # If found, this directory will be rsync'd to strongspace separately. If this folder does not exist then 
        # this feature will be ignored.
        # For a cron job that will create daily rolling MySQL backups, see http://textsnippets.com/posts/show/419
        DB_BACKUP_DIR=~/daily-sql-backup/

        STRONGSPACE_KEY=/home/YOURUSERNAME/.ssh/ss             # Private key file
        STRONGSPACE_USER=SSUSER                                  # Your strongspace login name
        STRONGSPACE_DOMAIN=SSDOMAIN.strongspace.com          # Your strongspace domain

        STRONGSPACE_WEB_BACKUP_DIR=private/backup/web/               # strongspace path for storing web file backups
        STRONGSPACE_DB_BACKUP_DIR=private/backup/databases/  # optional strongspace path for storing SQL backups
## End of configuration section

DOMAINS=`ls ~/domains`
for dom in $DOMAINS
do
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/domains/$dom/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom
done

if [ -d ~/public_html ]; then
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" ~/public_html/ $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_WEB_BACKUP_DIR/$dom
fi

if [ -d $DB_BACKUP_DIR ]; then
        /usr/local/bin/rsync -azq --delete -e "ssh -i $STRONGSPACE_KEY" $DB_BACKUP_DIR $STRONGSPACE_USER@$STRONGSPACE_DOMAIN:/home/$STRONGSPACE_USER/$STRONGSPACE_DB_BACKUP_DIR
fi

Daily MySQL backups on Textdrive, rotated weekly

This cron job will create a compressed backup of all the mysql databases under your account. The backup will be stored as "\daily-backup\Mon.gz" - and so forth, one for each day of the week. In this way you will have rotating backups going back seven days.

First, create the "daily-backup" folder under your home directory.

Go into the System - Cron Jobs section in webmin and paste this in as a new cron job (all one line)

/usr/local/bin/mysqldump --skip-opt -uUSERNAME -pPASSWORD --quote-names --complete-insert --extended-insert --quick --compact --lock-tables=false --skip-add-locks --all-databases | gzip > /home/USERNAME/daily-backup/sql-alldb-`date "+%a"`.gz 


Make sure to replace the USERNAME and PASSWORD with your own info.

You can set it up to run on any kind of daily schedule; I have it set to run daily at an early-morning time that I picked randomly.
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed