Pulvinar tempor cras amet ac turpis tristique tristique ... (read more)close
Pulvinar tempor cras amet ac turpis tristique tristique ... (read more)close

LukeTaylor.org Blog

Making I.T that little bit easier !

Linux Based Website Backup Script

by in Linux Blog
  • Font size: Larger Smaller
  • Hits: 6066
  • 1 Comment
  • Subscribe to this entry
  • Print
6066

b2ap3_thumbnail_blank_computer_screen.png

 

Not having much luck trying to find a automated backup script that not only backup the mysql database and web directory to a external mounted drive , i managed to find snippets of code off the net and put together one that also deletes files older than a specified amount of time .

 

Place the following in a file , use cron/crontab to automate. Make the folder in the root called Backups , inside this make a few folders called Database , Directorys and Script .

 #!/bin/sh
THEDB="DBNAME"
THEDBUSER="DBUSERNAME"
THEDBPW="DBPASSWORD"
THEDATE=`date +%d%m%y%H%M`
#Backup the database of website
mysqldump -u ${THEDBUSER} -p${THEDBPW} ${THEDB} | gzip > /Backups/Database/dbbackup_${THEDB}_${THEDATE}.bak.gz
#Backup the Folder of website
tar -czf /Backups/Directorys/Directory_backup_website_${THEDATE}.tar /var/html/www/website
#Delete old files more tha 180 days old
find /Backups/Directorys/Di* -mtime +60 -exec rm {} \;
find /Backups/Database/db* -mtime +60 -exec rm {} \;
Rate this blog entry:

Comments

  • Guest
    Barry Queen Tuesday, 01 October 2013

    Great Script ! Just what i needed .....

Leave your comment

Guest Tuesday, 19 November 2019