Skip to content

Instantly share code, notes, and snippets.

@sipofwater
Last active August 8, 2019 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sipofwater/9917e573c0839c81f6a787011505ba61 to your computer and use it in GitHub Desktop.
Save sipofwater/9917e573c0839c81f6a787011505ba61 to your computer and use it in GitHub Desktop.
rsync LAMP Server Config files and local web folder backup

The Purpose of filesystembackup.sh

is to create a backup of all LAMP server configuration files, shell scripts, web files, and MySQL databases as part of my Disaster Recovery Plan.

backup location(s):

  • /etc/apache2/apache2.conf to /web/backups/etc-apache2/apache2.conf

  • /etc/apache2/sites-available/ to /web/backups/etc-apache2/sites-available/

  • /etc/apache2/sites-enabled/ to /web/backups/etc-apache2/sites-enabled/

  • /etc/php/7.0/apache2/php.ini to /web/backups/etc-php-7.0-apache2/php.ini

  • /web/webroot/ to /web/backups/webroot

  • /web/scripts/ to /web/backups/scripts

  • /web/backup/mysql to /web/backups/mysql

which then:

  • rsyncs /web/backups to an external hard drive

To generate the MySQL database backups at /web/backup/mysql, this script also runs the newmysqlbackup.sh found at: https://blog.sleeplessbeastie.eu/2012/11/22/simple-shell-script-to-backup-mysql-databases/

assumptions

  • file structure created with installwebserver.sh) shell script.
  • external backup device is attached to the computer

Directory structure (created by running installwebserver.sh):

  • /web/
  • /web/backups/
  • /web/scripts/
  • /web/webroot/

dependancies required:

  • none

usage

  • sh filesystembackup.sh
  • there are no parameters

notes:

  • would like this to compress and upload to online storage service as well
  • backup npm/node/<other(s)> configurations(?)
#!/bin/bash
set -x # echo on
# Created: December 4, 2016
# Updated: January 7, 2018
# Purpose: To backup apache conf files, php.ini, scripts, web files,
# and mysql database backupsonto an external hard disk drive.
sudo rsync -av /etc/php/7.0/apache2/php.ini /web/backups/etc-php-7.0-apache2/php.ini --delete --progress
sudo rsync -av /etc/apache2/apache2.conf /web/backups/etc-apache2/apache2.conf --delete --progress
sudo rsync -av /etc/apache2/sites-available/ /web/backups/etc-apache2/sites-available/ --delete --progress
sudo rsync -av /etc/apache2/sites-enabled/ /web/backups/etc-apache2/sites-enabled/ --delete --progress
sudo rsync -r --exclude=.git /web/scripts/ /web/backups/scripts --delete --delete-excluded --progress
sudo rsync -r --exclude=.git /web/webroot/ /web/backups/webroot --delete --delete-excluded --progress
sudo sh /web/scripts/dev/newmysqlbackup.sh
sudo rsync -r /web/backups/ /media/jake/My\ Book/azrael/ --delete-after --delete --progress
### rclone wouldn't complete over several hours, rsync above took minutes!
# sudo rclone -v -L --exclude=.git --exclude=mysql copy /web/backups/ googledrive:azrael/ --delete-excluded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment