- 23
- Dec
original image by Just Taken Pics
Lets face it, no one likes performing manual backups. Often if monotonous tasks are not automated in some way (which they should be, that is why computers were invented) they will be forgotten and not performed regularly.
By using Linux wget and cron, we can incrementally backup websites and write a log file for each day. This will save time and network traffic.
This post features the same method I use to backup Hackosis on a daily basis.
Next, cd ~ into your home directory, or the location were you will be putting the website backup. create a new text file — touch websitebackup.sh. If you are backing up multiple websites, you may wish to name the file specific to the website you are backing up to avoid confusion.
Now execute chmod u+x websitebackup.sh to give the file execute permissions.
Contents of websitebackup.sh. Replace italics respectively:
# This script backs up the domain.com website
# Hackosis.com
#change directory into the backup location
cd /backup/path
#Backs up the website incrementally using wget into a folder of the ftp hostname
wget --output-file=logfile.log --tries=5 --passive-ftp --mirror --ftp-user=username \
--ftp-password=password ftp://ftp.yourftpsite.com
#Renames the logfile.log to logfile
mv logfile.log “logfile$(date +%Y%m%d%k%M).log”
NOTE: If the text above is not copying correctly for you, download it.
Next, we need to add the script to the crontab to be executed daily.
Now type the following into the crontab file:
Cron with then execute the specified command every night at 12:00am.
I hope this eases your website backup burdens. There are several ways to improve this including using the Linux mail command to email the log file — or maybe your could use grep to search the log file for failures, and just email that.
If you have any tips to improve this script, please drop a line in the comments. Thanks to dailycupoftech.com for the wget example.
Related Posts
Tags: Automation, Backup, Cron, Featured, Linux, Tutorials, Web development, Wget



December 31st, 2007 at 3:18 pm
[...] Quickies - website backup Filed under: Linux, Security, Technology — 0ddn1x @ 2007-12-31 20:18:03 +0000 http://www.hackosis.com/index.php/2007/12/23/linux-backup-your-website-automatically-with-wget-and-c... [...]
July 18th, 2008 at 9:52 am
thanks, it works
August 26th, 2008 at 9:02 pm
[...] Linux: Backup Your Website Automatically With Wget and Cron (tags: website backup cron wget ubuntu howto tutorial tutorials tips guides) [...]