Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. MyUSER="" # USERNAME
  2. MyPASS="" # PASSWORD
  3. MyHOST="localhost" # Hostname
  4.  
  5. # Backup Dest directory, change this if you have someother location
  6. DEST="/backup"
  7.  
  8. # Main directory where backup will be stored
  9. MBD="$DEST/mysql"
  10.  
  11. mkdir -p "$MBD"
  12.  
  13. # Get hostname
  14. HOST="$(hostname)"
  15.  
  16. # Get data in dd-mm-yyyy format
  17. NOW="$(date +"%d-%m-%Y")"
  18.  
  19. # File to store current backup file
  20. FILE=""
  21. # Store list of databases
  22. DBS=""
  23.  
  24. # DO NOT BACKUP these databases
  25. IGGY="information_schema"
  26.  
  27. # Only root can access it!
  28. chown 0.0 -R "$DEST"
  29. chmod 0600 "$DEST"
  30.  
  31. # Get all database list first
  32. DBS="$("$MYSQL" -u "$MyUSER" -h "$MyHOST" -p "$MyPASS" -Bse 'show databases')"
  33.  
  34. for db in $DBS
  35. do
  36. skipdb=-1
  37. if [ "$IGGY" != "" ];
  38. then
  39. for i in $IGGY
  40. do
  41. [ "$db" == "$i" ] && skipdb=1 || :
  42. done
  43. fi
  44.  
  45. if [ "$skipdb" == "-1" ] ; then
  46. FILE="$MBD/$db.$HOST.$NOW.tar"
  47. # do all inone job in pipe,
  48. # connect to mysql using mysqldump for select mysql database
  49. # and pipe it out to gz file in backup dir :)
  50. "$MYSQLDUMP" -u "$MyUSER" -h "$MyHOST" -p "$MyPASS" "$db" | gzip -9 > "$FILE"
  51. fi
  52. done
  53.  
  54. ########################################################################################
  55.  
  56. #This will backup ones home directory to /backup then cp to /mnt/backup and tar it
  57.  
  58. #specify the username for the home directory you want to backup
  59. userName=""
  60.  
  61. #user directory to backup
  62. homeDirectory="/home/$userName"
  63.  
  64. #main backup directory
  65. backupDestination="/backup"
  66.  
  67. #backup subdirectory
  68. subDir="$backupDestination/homeBackup"
  69.  
  70. mkdir -p "$subDir"
  71.  
  72. #naming convention for files
  73. fileName="$subDir/$userName.$NOW.tar"
  74.  
  75. #tars the file
  76. gzip -9 "$fileName"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement