Clicky

How to Backup Dreamhost Files and Email Them Using Cron

Backing up your website is one of the most important things you can do. No matter how much traffic or content your site has, if you loose it your website will decline rapidly. This tutorial will show you how to create a script to backup your files and email them to you regularly.

Backup your Dreamhost Files

Create Your Backup Location

  • Login to your FTP for your Dreamhost site. Then Create a folder called backup inside
  • In this folder create a folder with the name of your website

Create the Backup Script

  • Create a file called backup.sh and put the following code inside the file
suffix=$(date +%d_%m_%y)
tar -zcf /home/%username%/backup/benosullivan/ben.backup.$suffix.tar.gz /home/%username%/benosullivan.co.uk/
uuencode /home/%username%/backup/benosullivan/ben.backup.$suffix.tar.gz backup.$suffix.tar.gz | mailx -s "Email Title Goes Here" "Your email address goes here"
  • Change %username% to your FTP username
  • Change backup/benosullivan/ to the folder you created previously
  • Change /home/%username%/benosullivan.co.uk/ on the second line to the folder you want to backup
  • Finally change the email settings at the very end to meet your needs
  • Copy this file to your backup folder

Create your Cron Job

  • Login to your Dreamhost control panel. Select Cron Jobs under Goodies
dreamhost cron
  • Create a new Cron Job
  • In the command field enter the following command (Replace %username% with the same username as before)
/home/%username%/backup/backup.sh
  • Give it a name and select how often you want it to run
  • Well done! Your website will now automatically backup and email it to you