From ad0a42d800aa2f85a5cd46c5cec096742fed4ae8 Mon Sep 17 00:00:00 2001 From: Gogs Date: Sat, 25 Jun 2022 17:32:00 -0400 Subject: [PATCH] initial commit --- .gitignore | 2 + backupApache.sh | 34 ++++++++++++ backupElog.sh | 32 +++++++++++ backupWebPage.sh | 22 ++++++++ backupWiki.sh | 135 +++++++++++++++++++++++++++++++++++++++++++++++ wikiRestore.sh | 132 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 357 insertions(+) create mode 100644 .gitignore create mode 100755 backupApache.sh create mode 100755 backupElog.sh create mode 100755 backupWebPage.sh create mode 100755 backupWiki.sh create mode 100755 wikiRestore.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9db4ee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.tar.gz +*.tgz diff --git a/backupApache.sh b/backupApache.sh new file mode 100755 index 0000000..bfc010c --- /dev/null +++ b/backupApache.sh @@ -0,0 +1,34 @@ +#! /usr/bin/bash + +if [[ $UID != 0 ]]; then + echo "Please run this using sudo" + exit +fi + +prefix=backup_apache2 +fileName=$prefix-$(date +'%m-%d-%Y').tar.gz + +dir=$(pwd) + +echo "====== check number of old backup" +nBackup=$(ls -1 $prefix-* | wc -l) + +echo "number of backup : ${nBackup}" + +if [[ $nBackup -gt 3 ]]; then + oldFile=$(ls -t $prefix-* | tail -1) + echo "removing the old backup $oldFile" + rm -f $oldFile +fi + +echo "====== backup apache data" + +cd /etc + +tar -czf $fileName apache2/ + +ls -l $fileName + +mv $fileName $dir/. + +echo "backup saved to ${fileName}" diff --git a/backupElog.sh b/backupElog.sh new file mode 100755 index 0000000..54b5783 --- /dev/null +++ b/backupElog.sh @@ -0,0 +1,32 @@ +#! /usr/bin/bash + +if [[ $UID != 0 ]]; then + echo "Please run this using sudo" + exit +fi + +prefix=backup_elog +fileName=$prefix-$(date +'%m-%d-%Y').tar.gz + +dir=$(pwd) + +nFile=$(ls -1 $prefix* | wc -l) + +if [[ $nFile -gt 3 ]]; then + oldFile=$(ls -t $prefix* | tail -1) + echo "==== remove the old file $oldFile" + rm -f $oldFile +fi + + +echo "====== backup elog data" + +cd /mnt/data0/ + +tar -czf $fileName elog + +ls -l $fileName + +mv $fileName $dir/. + +echo "backup saved to ${fileName}" diff --git a/backupWebPage.sh b/backupWebPage.sh new file mode 100755 index 0000000..0c8a24b --- /dev/null +++ b/backupWebPage.sh @@ -0,0 +1,22 @@ +#! /usr/bin/bash + +if [[ $UID != 0 ]]; then + echo "Please run this using sudo" + exit +fi + +fileName=backup_WebPage-$(date +'%m-%d-%Y').tar.gz + +dir=$(pwd) + +echo "====== backup Web page data at /var/www/" + +cd /var/ + +tar -czf $fileName www/ + +ls -l $fileName + +mv $fileName $dir/. + +echo "backup saved to ${fileName}" diff --git a/backupWiki.sh b/backupWiki.sh new file mode 100755 index 0000000..c8dfa3d --- /dev/null +++ b/backupWiki.sh @@ -0,0 +1,135 @@ +#!/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 +'%m-%d-%Y'` + +# 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. " diff --git a/wikiRestore.sh b/wikiRestore.sh new file mode 100755 index 0000000..d9ad923 --- /dev/null +++ b/wikiRestore.sh @@ -0,0 +1,132 @@ +#!/bin/bash +# +# fullsiterestore.sh v1.0 +# +# Restore of website file and database content made with full site backup. +# +# A number of variables defining file location and database connection +# information must be set before this script will run. +# This script expects a compressed tar file (tgz) made by fullsitebackup.sh. +# Website files should be in a tar file named filecontent.tar, and database +# content should be in a sqldump sql file named dbcontent.sql. This script +# expects the sql to drop the table before readdding the data. In other words, +# it does not do any database preparation. +# +# Parameters: +# tar_file_name + +# +# Configuration +# + +# Database connection information + dbname={my_wiki} # (e.g.: dbname=drupaldb) + dbhost=localhost + dbuser={wikiadmin} # (e.g.: dbuser=drupaluser) + +# Website Files + webrootdir={/data0/mediawiki} # (e.g.: webrootdir=/home/user/public_html) + + +# +# Variables +# + +# Execution directory (script start point) + startdir=`pwd` + +# Temporary Directory + datestamp=`date +'%Y-%m-%d'` + tempdir=tmpbckdir$datestamp + + +# +# Banner +# +echo "" +echo "fullsiterestore.sh v1.0" + + +# +# Input Parameter Check +# + +# If no input parameter is given, echo usage and exit +if [ $# -eq 0 ] + then + echo " Usage: sh fullsiterestore.sh {backupfile.tgz}" + echo "" + exit +fi + +tarfile=$1 + +# Check that the file exists +if [ ! -f "$tarfile" ] + then + echo " Can not find file: $tarfile" + echo "" + exit +fi + +# Check that the webroot directory exists +if [ ! -d "$webrootdir" ] + then + echo " Invalid internal parameter: webrootdir" + echo " Directory: $webrootdir does not exist" + echo "" + exit +fi + + +# +# Create temporary working directory and expand tar file +# +echo " .. Setup" +mkdir $tempdir +cd $tempdir +tar xzf $startdir/$tarfile +echo " done" + + +# +# Remove old website files +# +echo " .. removing old files from $webrootdir" +rm -r $webrootdir/* +echo " done" + + +# +# unTAR website files +# +echo " .. unTARing website files into $webrootdir" +cd $webrootdir +tar xf $startdir/$tempdir/filecontent.tar +echo " done" + + +# +# Load database information +# +cd $startdir/$tempdir +echo " .. loading database:" +echo " user: $dbuser; database: $dbname; host: $dbhost" +echo "use $dbname; source dbcontent.sql;" | mysql --password --user=$dbuser --host=$dbhost +echo " done" + + +# +# Cleanup +# +echo " .. Clean-up" +cd $startdir +rm -r $tempdir +echo " done" + + +# +# Exit banner +# +echo " .. Full site restore complete" +echo ""