Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Site name
  4. site_name="sitename.com"
  5.  
  6. # Database credentials
  7. user="db_user"
  8. password="super_secret_pass"
  9. host="localhost"
  10. db_name="db_name"
  11.  
  12. # Files source
  13. files_src_dir="/path/to/$site_name/"
  14.  
  15. # Backup path
  16. backup_path="/path/to/backups/"
  17.  
  18.  
  19. # You shouldn't need to edit anything below this line
  20.  
  21. # Set the date
  22. date=$(date +"%d-%b-%Y")
  23.  
  24. # Set today's backup path
  25. today_backup_path=$backup_path$site_name-$date
  26.  
  27. # Create today's backup directory
  28. mkdir $today_backup_path
  29.  
  30.  
  31. # Set default file permissions
  32. umask 177
  33.  
  34. # Dump database into SQL file
  35. mysqldump --user=$user --password=$password --host=$host $db_name > $today_backup_path/$db_name-$date.sql
  36.  
  37. # Copy the srouce directory files to today's backup path
  38. cp -a $files_src_dir. $today_backup_path
  39.  
  40. # TAR the archive
  41. tar -zcf $today_backup_path.tar.gz $today_backup_path
  42.  
  43. # Now remove the directory that we used to create the archive
  44. rm -rf $today_backup_path
  45.  
  46.  
  47. # Delete files older than 15 days
  48. find $backup_path/* -mtime +15 -exec rm {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement