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. 

Sign in to follow this  
Mopar1973Man

Backing up your web server to Home PC

Recommended Posts

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

Share this post


Link to post
Share on other sites
Sign in to follow this  




×
×
  • Create New...