Sunday, May 20, 2012
 

Linux site/mysql backup script with automation old files rotation

Just small script that does automatickly backups of selected site including database. And makes automatickly backup rotation.

So small script that does all that. Do not foger replace "/home/www" and /misc folders and others variables <variable> with your own. Files are deleted older than 7 days.

#!/bin/sh
echo Backup Started `date`
# Paths
baseDirBackup=/misc
targetDir=/home/www

# Mysql configuration
usernameMysql=<username>
passwordMysql=<password>
databaseMysql=<database>

dirBackup=$baseDirBackup/`date +%Y%m%d`
mkdir $dirBackup
tar czf $dirBackup/dump.tar.gz $targetDir
mysqldump -u $usernameMysql --password=$passwordMysql --default-character-set=utf8 $databaseMysql > $baseDirBackup/`date +%Y%m%d`/dump_db.sql
find $baseDirBackup -mtime +7 -delete
echo Backup Completed `date`

 After placing all that you can setup cronjob command to make backup every night.

Back »

Comments: 0

Leave a reply »

 
  • Leave a Reply
    Your gravatar
    Your Name
     
     
     
     
 
About Remdex site

Simple site for simple peoples.

Get in touch

E-mail: remdex@gmail.com