Post: [BASH] Backup Creator for Site/DB
04-11-2016, 01:31 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); This bash script backups the database and site. You must change some of the BASH VARIABLES but it should be easy. If you experience any problems just ask for help. You can create automatic backups as well with this. You must modify crontabs to do so.

Requirements

  1. MySQL Server
  2. tar and gzip


    
#!/bin/bash
# Creates a backup of sites automatically
# we store the backup in the specified directory.
# Version 1.0
# Project Date 01/11/2016

BACKUP_DIR="/www/backup"
BACKUP_TIME=(`date +"%m-%d-%y"`)
BACKUP_FILE+="SiteName_"
BACKUP_FILE+=$BACKUP_TIME
BACKUP_FILE+=".tar.gz"
BACKUP_TARGET="/www/sitename"
MYSQL_USER="DB USER"
MYSQL_PASS="DB PASS"
MYSQL_DB="DB NAME"
MYSQL_FILE="SiteName_"
MYSQL_FILE+=$BACKUP_TIME
MYSQL_FILE+=".sql"

echo "Backing up site files."
tar -zcf $BACKUP_DIR/$BACKUP_FILE $BACKUP_TARGET > /dev/null 2>&1
echo "Site has been backed up."
echo "Backing up the MySQL Database."
mysqldump --user=$MYSQL_USER --password=$MYSQL_PASS $MYSQL_DB > $BACKUP_DIR/$MYSQL_FILE > /dev/null 2>&1
echo "Finished backing up MySQL Database."
echo "Compressing Database."
gzip $BACKUP_DIR/$MYSQL_FILE > /dev/null 2>&1
echo "Finished Compression of Database."

echo "Finished Daily backup"

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo