Better rsync backup script
#!/bin/bash
# Basic backup script
# Written in February 2010
# Set to q to disable verbosity
VERBOSITY="v"
# The program we're using to backup
PROGRAM="rsync"
# The arguments to the program
OPTIONS="-aHP$VERBOSITY"
# The remote machine we're backing up
SERVER="max"
# The local disk to back up to
DISK="/mnt/disk"
# An array of shares on $SERVER to back up
SHARES=(
hr
finance
clients
operations
newsvn
svn
backup/jira
backup/svn/noah
backup/dbbackups/kontrol_live
backup/dbbackups/god
)
# The magic
for share in ${SHARES[*]}; doMysql + PostgreSQL 'all databases' backup script
Backup script to find and backup all databases (postgres and mysql)
#!/bin/bash
today=$(date +%y%m%d)
# local dir where the backups go
myDir='/data/dbbackups'
# remote dir where we'll send them offsite
myRemoteDir='/data/backup/li35-166/dbbackups'
# this is for PostgreSQL. If you don't need it, you
# could leave it here, but remove the 'backup_pgsql'
# function call at the end of the script
function backup_pgsql {
for db in `su postgres -c "psql -U postgres -qAtc '\l'" | cut -f1 -d\|
| grep -v '^template[01]'`; do
mkdir -p $myDir/${db};rsync backup script
VERY simple rsync script. It rsyncs a remote directory across to a local one. There's no special reason why I did this, other than I wanted to run the script on my local machine. It could just as easily rsync a local directory to a remote one.
#!/bin/sh
export RSYNC_RSH=/usr/bin/ssh
origin=remote.machine.com # the remote machine to rsync from
user=miguel # the remote user
rsync -aHPvz "${user}@${origin}:/remote/files/" "/local/files/"I run ssh-keygen -t rsa and create a password-less key on the remote machine, and copy the .pub file into my authorized_keys. This way I can run this script on a cron, say in the middle of the night, and not have to be around to enter a password at the prompt.
Backup of subversion repository
This script does an svn hotcopy of a subversion repository and then rsyncs it to an external location. Easy to script, nice trouble-free way of maintaining subversion backups.
#!/bin/bash
export RSYNC_RSH=/usr/bin/ssh
# some variables in case they change later
server=destination.com # where we are sending the backup to
user=miguel
tempcopy=/home/${user}/svnbackup
dest=/media/disk/svnserver/svnbackup
# example svn repository
# make the backup with svnadmin hotcopy
svnadmin hotcopy /data1/svn/repo/ ${tempcopy}/repo/
# rsync it to the external hard drive on my desk
rsync -aHPvz ${tempcopy}/repo/ "${user}@${server}:${dest}/repo/"
# finally, remove the backup on svnserver to free up some space
rm -rf ${tempcopy}/repoHourly database backup
#!/bin/bash DATE=`date +%H` FILENAME=$1/$1_hourly_$DATE.sql mkdir -p $1 pg_dump -cxO -f $FILENAME $1 gzip -f $FILENAME echo $FILENAME
