Jump to content
  • Welcome To Mopar1973Man.Com

    We can see that your guest and been lurking about. When you register on the Mopar1973Man.Com site you'll be able to interact with all the other members. This is the most friendliest Cummins forum you'll ever join. Take the time right now and  REGISTER  on the Mopar1973Man.Com this will open up many more options and functions on the website. Everyone is very friendly and helpful just ask questions and everyone will help you out the best they can. 

Backing up your web server to Home PC

Recommended Posts

  • Administrator
Posted (edited)

Here is a page from nixCraft that is super simple and covers everything for you. Compressing the files, making one compressed file to send, even backs up your MySQL data too. 




The only twist I love to do this is set the shell script in a root folder and root permissions. Now setup Anacron to run that shell script every day or every week. The system will not ask for passwords or prompt you if the script is correct. It should run quietly in the background doing it job once a day or once a week.


Cron vs. Anacron. Cron will require the machine to be on at the set time every day it suppose to run. If the time is missed the script does not run period.  Anacron if you miss the run time it will still run the shell script if missed then flags that the script has ran for this period and waits for the next period. Not time or date sensitive.


# A Simple Shell Script to Backup Red Hat / CentOS / Fedora / Debian / Ubuntu Apache Webserver and SQL Database
# Path to backup directories
DIRS="/home/vivek/ /var/www/html/ /etc"
# Store todays date
NOW=$(date +"%F")
# Store backup path
# Backup file name hostname.time.tar.gz 
BFILE="$(hostname).$(date +'%T').tar.gz"
PFILE="$(hostname).$(date +'%T').pg.sql.gz"
MFILE="$(hostname).$(date +'%T').mysql.sq.gz"
# Set Pgsql username
# Set MySQL username and password
# Remote SSH server setup
SSHSERVER="backup.example.com" # your remote ssh server
SSHUSER="vivek"                # username   
SSHDUMPDIR="/backup/remote"    # remote ssh server directory to store dumps
# Paths for binary files
# make sure backup directory exists
[ ! -d $BACKUP ] && mkdir -p ${BACKUP} 
# Log backup start time in /var/log/messages
$LOGGER "$0: *** Backup started @ $(date) ***"
# Backup websever dirs
$TAR -zcvf ${BACKUP}/${BFILE} "${DIRS}"
# Backup PgSQL
# Backup MySQL
$MYSQLDUMP  -u ${MYSQLUSER} -h localhost -p${MYSQLPASSWORD} --all-databases | $GZIP -9 > ${BACKUP}/${MFILE}
# Dump all local files to failsafe remote UNIX ssh server / home server
# Log backup end time in /var/log/messages
$LOGGER "$0: *** Backup Ended @ $(date) ***"


Edited by Mopar1973Man
Link to post
Share on other sites

  • Create New...