LAMP Backup Script

#!/bin/bash
#
# my_backup.sh V1.0
#
# An useful script that performs a variety of operations in order to backup different data.
# It’s a good starting point for your bespoke one

# Creating all the definitions
datestamp=$(date +’%Y%m%d%H%M%S’)
tarname=my_backup-$datestamp”.tgz”
tempdir_base=tmpbckdir$datestamp
tempdir=*/var/tmp_backups/*$tempdir_base
tempdir_db=$tempdir”/db”

# Creating the directories for the operations
mkdir $tempdir
mkdir $tempdir_db

# Backuping databases
mysqldump -u *superuser* -p*superuser_psw* *database1* | gzip –best > $tempdir_db/*database1*.sql.gz
mysqldump -u *superuser* -p*superuser_psw* *database2* | gzip –best > $tempdir_db/*database2*.sql.gz
mysqldump -u *superuser* -p*superuser_psw* *database3* | gzip –best > $tempdir_db/*database3*.sql.gz

# Backuping databases – There are a lot of databases called like this: user_user1, user_user2,…
cd /var/lib/mysql/
for i in $( echo user_* ); do
mysqldump -u *superuser* -p*superuser_psw* $i > $tempdir_db/$i.sql
done

# Backuping files
cp -ra *dir1* $tempdir/*dir1*
cp -ra *dir2* $tempdir/*dir2*

# Sending a mail with the content of a log file
mutt -s “log file” -a *file_path* *mail address* < *file_path*
# truncating the file
echo “” > *file_path*

# Storing the compressed backup in a local disk
mount /dev/hdc1 /mnt
cd /etc/sm_it
tar czf /mnt/$tarname $tempdir_base
umount /mnt

# Deleting the temp files
rm -r $tempdir

LAMP Backup Script

This entry was posted in LAMP Server Setup, System Maintenance. Bookmark the permalink.

Leave a Reply