Giter Club home page Giter Club logo

full-web-server-backup's Introduction

Web Server Backup Script

This is a bash script for backing up multiple web sites, MySQL databases and /etc/ into a specified backups directory.

Once configured (variables set within the script), it does this:

  • Creates a directory for your site (file) backups (if it doesn't exist) with option for exclude;
  • Creates a directory for your MySQL dumps (if it doesn't exist);
  • Loops through all of your MySQL databases and dumps each one of them to a gzipped file;
  • Creates a directory for your configurations (/etc/) (if it doesn't exist);
  • Tars and gzips each folder within your sites directory (I keep my websites in /var/www/html/).

BETA WARNING

___This script works fine for me (using Ubuntu 16.04.3 LTS on Vultr and selfhosted), but servers vary greatly. USE THIS SCRIPT AT YOUR OWN RISK! There is always risk involved with running a script. I AM NOT RESPONSIBLE FOR DAMAGE CAUSED BY THIS SCRIPT. For this reason I removed the delete functionality from the project I forked. ___

You may very well know more about bash scripting and archiving than I do. If you find any flaws with this script or have any recommendations as to how this script can be improved, please fork it and send me a pull request.

Installation

  • MOST IMPORTANTLY: Open the backup.sh file in a text editor and set the configuration variables at the top (see below).
  • Optionally, edit the tar command on line 97 to add some more --exclude options (e.g. --exclude="cache/*")
  • Place the backup.sh file somewhere on your server (something like /opt/full-web-server-backup).
  • Make sure the backup.sh script is executable by root: sudo chmod 744 /opt/full-web-server-backup/backup.sh
  • Preferably set up cron to run it every night (see below).

Configuration

There are a bunch of variables that you can set to customize the way the script works. Some of them must be set before running the script!

NOTE: The BACKUP_DIR setting is preset to /backups/site-backups. If you want to use something like /var/site-backups, you'll need to create the directory first and set it to be writable by you.

General Settings:

  • BACKUP_DIR: The parent directory in which the backups will be placed. It's preset to: "/backups/site-backups"
  • KEEP_MYSQL: How many days worth of mysql dumps to keep. It's preset to: "14"
  • KEEP_SITES: How many days worth of site tarballs to keep. It's preset to: "2"

MySQL Settings:

  • MYSQL_HOST: The MySQL hostname. It's preset to the standard: "localhost"
  • MYSQL_USER: The MySQL username. It's preset to the standard: "root"
  • MYSQL_PASS: The MySQL password. You'll need to set this yourself!
  • MYSQL_BACKUP_DIR: The directory in which the dumps will be placed. It's preset to: "$BACKUP\_DIR/mysql/"

Web Site Settings:

  • SITES_DIR: This is the directory where you keep all of your web sites. It's preset to: "/var/www/html/"
  • SITES_BACKUP_DIR: The directory in which the archived site files will be placed. It's preset to: "$BACKUP_DIR/sites/"

Date format: (change if you want)

  • THE_DATE: The date that will be appended to filenames. It's preset to: "$(date '+%Y-%m-%d')" (2017-11-07)

Paths to commands: (probably won't need to change these)

  • MYSQL_PATH: Path to mysql. It's preset to: "$(which mysql)"
  • MYSQLDUMP_PATH: Path to mysqldump. It's preset to: "$(which mysqldump)"
  • FIND_PATH: Path to find. It's preset to: "$(which find)"
  • TAR_PATH: Path to tar. It's preset to: "$(which tar)"
  • RSYNC_PATH: Path to rsync. It's preset to: "$(which rsync)"

TODOs

  • Cron;
  • External password file usage (in ~/.my.cnf);
  • Define compression level for each task (mySQL, DB, configuration);
  • Include/exclude specific directories (for example archive only /etc/nginx and /etc/mySQL directories);
  • Keep n number of files or add verification for disk space + email to admin if disk is low on space.

full-web-server-backup's People

Contributors

postpostmodern avatar nedkohristov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.