Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #################################################################
  4. #                       Edit the Following                      #
  5. #################################################################
  6. sql_user="root"
  7. sql_pass="7gatu9KAopen"
  8. sql_host="localhost"
  9.  
  10. # Files you want to backup
  11. backup_files="/home /var/vmail /var/www"
  12.  
  13. #################################################################
  14. #                           Do NOT Touch                        #
  15. #################################################################
  16.  
  17. # Linux bin paths, change this if it can not be autodetected via which command
  18. MYSQL="$(which mysql)"
  19. MYSQLDUMP="$(which mysqldump)"
  20. CHOWN="$(which chown)"
  21. CHMOD="$(which chmod)"
  22. GZIP="$(which gzip)"
  23.  
  24. # Get data in dd-mm-yyyy format
  25. NOW="$(date +"%d-%m-%Y")"
  26.  
  27. # Backup Dest directory, change this if you have someother location
  28. DEST="/backup/$NOW"
  29.  
  30. # Main directory where backup will be stored
  31. MBD="$DEST/mysql"
  32.    
  33. # File to store current backup file
  34. FILE=""
  35.  
  36. # Store list of databases
  37. DBS=""
  38.  
  39. # DO NOT BACKUP these databases
  40. IGGY=""
  41.  
  42. [ ! -d $MBD ] && mkdir -p $MBD || :
  43.  
  44. # Only root can access it!
  45. $CHOWN 0.0 -R $DEST
  46. $CHMOD 0600 $DEST
  47.  
  48. # Get all database list first
  49. DBS="$($MYSQL -u $sql_user -h $sql_host -p$sql_pass -Bse 'show databases')"
  50.  
  51. for db in $DBS
  52. do
  53.     skipdb=-1
  54.     if [ "$IGGY" != "" ];
  55.     then
  56.     for i in $IGGY
  57.     do
  58.         [ "$db" == "$i" ] && skipdb=1 || :
  59.     done
  60.     fi
  61.  
  62.     if [ "$skipdb" == "-1" ] ; then
  63.     FILE="$MBD/$db.gz"
  64.     # do all inone job in pipe,
  65.     # connect to mysql using mysqldump for select mysql database
  66.     # and pipe it out to gz file in backup dir :)
  67.         $MYSQLDUMP -u $sql_user -h $sql_host -p$sql_pass $db | $GZIP -9 > $FILE
  68.     fi
  69. done
  70.  
  71. # Create archive filename.
  72. archive_file="backup.tgz"
  73.  
  74. # Print start status message.
  75. echo "Backing up $backup_files to $DEST/$archive_file"
  76. date
  77. echo
  78.  
  79. # Backup the files using tar.
  80. tar czf $DEST/$archive_file $backup_files
  81.  
  82. # Print end status message.
  83. echo
  84. echo "Backup finished"
  85. date
  86.  
  87. # Long listing of files in $DEST to check file sizes.
  88. ls -lh $DEST
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement