Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Site name
- site_name="sitename.com"
- # Database credentials
- user="db_user"
- password="super_secret_pass"
- host="localhost"
- db_name="db_name"
- # Files source
- files_src_dir="/path/to/$site_name/"
- # Backup path
- backup_path="/path/to/backups/"
- # You shouldn't need to edit anything below this line
- # Set the date
- date=$(date +"%d-%b-%Y")
- # Set today's backup path
- today_backup_path=$backup_path$site_name-$date
- # Create today's backup directory
- mkdir $today_backup_path
- # Set default file permissions
- umask 177
- # Dump database into SQL file
- mysqldump --user=$user --password=$password --host=$host $db_name > $today_backup_path/$db_name-$date.sql
- # Copy the srouce directory files to today's backup path
- cp -a $files_src_dir. $today_backup_path
- # TAR the archive
- tar -zcf $today_backup_path.tar.gz $today_backup_path
- # Now remove the directory that we used to create the archive
- rm -rf $today_backup_path
- # Delete files older than 15 days
- find $backup_path/* -mtime +15 -exec rm {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement