Jump to content
  • Welcome To Mopar1973Man.Com

    We can see you are lurking about reading the forums and article databases. We happen to be one of the most friendliest Cummins support website on the planet. Come on and register and grab a inexpensive subscription plan. With that you can unlock even more for you. Technical support either by public forum, private support ticket, and even unlock phone support by Mopar1973Man. Mopar1973Man.Com will remain FREE to read forever!

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. 

 

https://www.cyberciti.biz/faq/how-to-back-up-a-web-server/

 

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.

 

#!/bin/bash
# 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="/backup/$NOW"
 
# 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
PGSQLUSER="vivek"
 
# Set MySQL username and password
MYSQLUSER="vivek"
MYSQLPASSWORD="myPassword"
 
# 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
TAR="/bin/tar"
PGDUMP="/usr/bin/pg_dump"
MYSQLDUMP="/usr/bin/mysqldump"
GZIP="/bin/gzip"
SCP="/usr/bin/scp"
SSH="/usr/bin/ssh"
LOGGER="/usr/bin/logger"
 
 
# 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
$PGDUMP -x -D -U${PGSQLUSER} | $GZIP -c > ${BACKUP}/${PFILE}
 
# 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
$SSH ${SSHUSER}@${SSHSERVER} mkdir -p ${SSHDUMPDIR}/${NOW}
$SCP -r ${BACKUP}/* ${SSHUSER}@${SSHSERVER}:${SSHDUMPDIR}/${NOW}
 
# 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...