Basic web server backup script – MySQL and Apache

I was working on a dedicated server the other day and needed a quick script to backup the website and the MySQL database. The following bash script will do just that, simply modify the directory paths within the tar command to ensure every folder you need is included, the MySQL command assumes all databases need to be backed up and that it should run as root.

In an ideal world you should modify this script to run within the context of a dedicated backup account.

#!/bin/bash
# quickbackup.sh - R. Jervis - Quick (sample) webserver backup script

cd /backup
mysqldump --all-databases > dump-$( date '+%Y-%m-%d_%H-%M-%S' ).sql -u root -p
tar -cvzf backup-$( date '+%Y-%m-%d_%H-%M-%S' ).tar.gz /var/www/html/ /etc/apache2/ /etc/ssl/ /etc/php5/
(Visited 2,424 times, 1 visits today)
Facebooktwittergoogle_plusredditpinterestlinkedinmail