Hello All,
I found this as a Google cached page. It used to be on the old TLUG site (originally posted on Monday, May 05, 2003 - 03:38) so I have reposted here.
Regards, Bawdo2001
I have put a copy of a backup script here that is
similar to the one we used for the TLUG site (before it was relocated). I have changed the
directory names and whatnot for security reasons.
You can alter and use this script to back up any directory or DB that you need to.
#!/bin/bash
# /usr/bin/backup
# Backup script for Directory X and PHP Include Files
# The following MySQL databses are also backed up:
# DB_NAME
#
# DATE: 05/05/2003
#################################
# Assign DTG and Date variables #
# to $a & $b respectively #
#################################
a=$(date +%T-%d_%m_%Y)
b=$(date +%d_%m_%Y)
########################################
# Backup Site Directory - files and db #
########################################
mkdir /directory/to/backup/to/$b/
# To copy only - nil archiving nil compression uncomment the next line
# cp -i -p -R /directory/to/be/backed/up /directory/to/backup/to/$b/name_of_bup.$a
# Archiving using tar, compression using bz2 all permissions kept in tact
tar pcjf "/directory/to/backup/to/$b/name_of_bup_file.tar.bz2" "/directory/to/be/backed/up"
mysqldump --password=password DB_NAME > /directory/to/backup/to/$b/name_of_bup_file.sql
echo "Back up of the X directory is complete"
#######################
# Backup PHP Includes #
#######################
mkdir /directory/to/backup/to/$b/includes/
# To copy only - nil archiving nil compression - uncomment the next line
# cp -i -p -R /directory/containing/includes/ /directory/to/backup/to/$b/includes/
# Archiving using tar, compression using bz2 all permissions kept in tact
tar pcjf " /directory/to/backup/to/$b/includes.tar.bz2" " /directory/containing/includes/"
echo "Back up of PHP include files are complete"
################################
# Email confirmation of backup #
################################
# Write files created during this backup to mail.txt
echo -e "Backup of Directory X, and php include files is completed for $b. \n
The following files were written:\n
\t\t\t /directory/to/backup/to/$b/name_of_bup_file.tar.bz2\n
\t\t\t /directory/to/backup/to/$b/name_of_bup_file.sql\n
\t\t\t /directory/to/backup/to/$b/includes.tar.bz2 \n\n
\n" > /directory/to/backup/to/mail.txt
# Append current disk usage of the backup directory to mail.txt
du -ch /directory/to/backup/to/ >> /directory/to/backup/to/mail.txt
echo -e "\n\n END OF MESSAGE" >> /directory/to/backup/to/mail.txt
# Send mail.txt as an email
cat /directory/to/backup/to/mail.txt | mail -s "Backup completed at $a" john.citizen@example.com