141 lines
3.5 KiB
Bash
Executable File
141 lines
3.5 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# fullsitebackup.sh V1.1
|
|
#
|
|
# Full backup of website files and database content.
|
|
#
|
|
# A number of variables defining file location and database connection
|
|
# information must be set before this script will run.
|
|
# Files are tar'ed from the root directory of the website. All files are
|
|
# saved. The MySQL database tables are dumped without a database name and
|
|
# and with the option to drop and recreate the tables.
|
|
#
|
|
# ----------------------
|
|
# March 2007 Updates
|
|
# - Updated script to resolve minor path bug
|
|
# - Added mysql password variable (caution - this script file is now a security risk - protect it)
|
|
# - Generates temp log file
|
|
# - Updated backup and restore scripts have been tested on Ubunutu Edgy server w/Drupal 5.1
|
|
#
|
|
# - Enjoy! BristolGuy
|
|
#-----------------------
|
|
#
|
|
## Parameters:
|
|
# tar_file_name (optional)
|
|
#
|
|
#
|
|
# Configuration
|
|
#
|
|
|
|
if [[ $UID != 0 ]]; then
|
|
echo "Please run with sudo"
|
|
exit
|
|
fi
|
|
|
|
# Database connection information
|
|
dbname="my_wiki" # (e.g.: dbname=drupaldb)
|
|
dbhost="localhost"
|
|
dbuser="wikiadmin" # (e.g.: dbuser=drupaluser)
|
|
dbpw="fsuphysics-888" # (e.g.: dbuser password)
|
|
|
|
# Website Files
|
|
webrootdir="/data0/mediawiki" # (e.g.: webrootdir=/home/user/public_html)
|
|
|
|
#
|
|
# Variables
|
|
#
|
|
|
|
# Default TAR Output File Base Name
|
|
tarnamebase=backup_wiki-
|
|
datestamp=`date +'%Y%m%d'`
|
|
|
|
# Execution directory (script start point)
|
|
startdir=`pwd`
|
|
logfile=$startdir"/wikibackup.log" # file path and name of log file to use
|
|
|
|
|
|
# Temporary Directory
|
|
tempdir=$datestamp
|
|
|
|
#
|
|
# Input Parameter Check
|
|
#
|
|
|
|
if test "$1" = ""
|
|
then
|
|
tarname=$tarnamebase$datestamp.tgz
|
|
else
|
|
tarname=$1
|
|
fi
|
|
|
|
#
|
|
# Begin logging
|
|
#
|
|
echo "Beginning wiki site backup using wikibackup.sh ..." > $logfile
|
|
echo "Beginning wiki site backup using wikibackup.sh ..."
|
|
|
|
#
|
|
# Check number of backup
|
|
#
|
|
|
|
nFile=$(ls -1 $tarnamebase* | wc -l)
|
|
echo "Number of existing backup = $nFile" > $logfile
|
|
echo "Number of existing backup = $nFile"
|
|
if [[ $nFile -gt 3 ]]; then
|
|
oldFile=$(ls -t $tarnamebase* | tail -1)
|
|
echo "Removing the oldest backup : $oldFile" > $logfile
|
|
echo "Removing the oldest backup : $oldFile"
|
|
rm -f $oldFile
|
|
fi
|
|
|
|
#
|
|
# Create temporary working directory
|
|
#
|
|
echo " Creating temp working dir ..." >> $logfile
|
|
mkdir $tempdir
|
|
|
|
#
|
|
# TAR website files
|
|
#
|
|
echo " TARing website files into $webrootdir ..." >> $logfile
|
|
echo " TARing website files into $webrootdir ..."
|
|
cd $webrootdir
|
|
tar cf $startdir/$tempdir/filecontent.tar .
|
|
|
|
#
|
|
# sqldump database information
|
|
#
|
|
echo " Dumping mysql database, using ..." >> $logfile
|
|
echo " Dumping mysql database, using ..."
|
|
echo " user:$dbuser; database:$dbname host:$dbhost " >> $logfile
|
|
echo " user:$dbuser; database:$dbname host:$dbhost "
|
|
cd $startdir/$tempdir
|
|
mysqldump --user=$dbuser --password=$dbpw --add-drop-table $dbname > dbcontent.sql
|
|
|
|
#
|
|
# Create final backup file
|
|
#
|
|
echo " Creating final compressed (tgz) TAR file: $tarname ..." >> $logfile
|
|
echo " Creating final compressed (tgz) TAR file: $tarname ..."
|
|
tar czf $startdir/$tarname filecontent.tar dbcontent.sql
|
|
|
|
#
|
|
# Cleanup
|
|
#
|
|
echo " Removing temp dir $tempdir ..." >> $logfile
|
|
echo " Removing temp dir $tempdir ..."
|
|
cd $startdir
|
|
rm -r $tempdir
|
|
|
|
#
|
|
# Exit banner
|
|
#
|
|
endtime=`date`
|
|
echo "Backup completed $endtime, TAR file at $tarname. " >> $logfile
|
|
echo "Backup completed $endtime, TAR file at $tarname. "
|
|
|
|
|
|
echo "===== ssh to newton.physics.fsu.edu"
|
|
cd $startdir
|
|
scp -rp $tarname ryan@128.186.111.52:/backupHome/.
|