Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.46 KB | None | 0 0
  1. tar: *.sql: Cannot stat: No such file or directory
  2. tar: Error exit delayed from previous errors
  3. tar: Cowardly refusing to create an empty archive
  4. Try `tar --help' or `tar --usage' for more information.
  5.  
  6. SCRIPT BELOW
  7.  
  8. #!/bin/bash
  9.  
  10. MyUSER=""     # USERNAME
  11. MyPASS=""       # PASSWORD
  12. MyHOST="localhost"          # Hostname
  13.  
  14. # Backup Dest directory, change this if you have someother location
  15. DEST="/backup"
  16.  
  17. # Main directory where backup will be stored
  18. MBD="$DEST/mysql"
  19.  
  20. mkdir -p "$MBD"
  21.  
  22. # Get hostname
  23. HOSTNAME="$(hostname)"
  24.  
  25. # Get data in dd-mm-yyyy format
  26. NOW="$(date +"%d-%m-%Y")"
  27.  
  28. # File to store current backup file
  29. FILE=""
  30. # Store list of databases
  31. DBS=""
  32.  
  33. # DO NOT BACKUP these databases
  34. IGGY="information_schema"
  35.  
  36. # Only root can access it!
  37. chown 0.0 -R "$DEST"
  38. chmod 0700 "$DEST"
  39.  
  40. # Get all database list first
  41. DBS="$("$MYSQL" -u "$MyUSER" -h "$MyHOST" -p "$MyPASS" -Bse 'show databases')"
  42.  
  43. for db in $DBS
  44. do
  45.     skipdb=-1
  46.     if [ "$IGGY" != "" ];
  47.     then
  48.     for i in $IGGY
  49.     do
  50.         [ "$db" == "$i" ] && skipdb=1 || :
  51.         done
  52.     fi
  53.  
  54.     if [ "$skipdb" == "-1" ] ; then
  55.     FILE="$MBD/$db.$HOSTNAME.$NOW.sql"
  56.     # do all inone job in pipe,
  57.     # connect to mysql using mysqldump for select mysql database
  58.     # and pipe it out to gz file in backup dir :)
  59.         "$MYSQLDUMP" -u "$MyUSER" -h "$MyHOST" -p "$MyPASS" "$db" > "$FILE"
  60.    fi
  61. done
  62.  
  63. tar -zcf mysqlBackup."$NOW".tar.gz *.sql
  64.  
  65. ########################################################################################
  66.  
  67. #This will backup ones home directory to /backup then cp to /mnt/backup and tar it
  68.  
  69. #specify the username for the home directory you want to backup
  70. userName=""
  71.  
  72. #user directory to backup
  73. homeDirectory="/home/$userName"
  74.  
  75. #main backup directory
  76. backupDestination="/backup"
  77.  
  78. #backup subdirectory
  79. subDir="$backupDestination/homeBackup"
  80.  
  81. mkdir -p "$subDir"
  82.  
  83. cp -r "$homeDirectory" "$subDir"
  84.  
  85. #naming convention for files
  86. fileName="$subDir/$userName.$NOW.tar.gz"
  87.  
  88. #tars the file
  89. tar -zcf "$fileName"
  90.  
  91. #checks to see if the directory exists otherwise it creats the directory
  92. mkdir -p /mnt/backup/
  93.  
  94. #this copies recursivly the backup directory and subdirectories to /mnt/backup
  95. cp -r /backup /mnt/backup/
  96.  
  97. ########################################################################################
  98.  
  99. #will check to see if files are older than 8 days if older then 8 days they are deleted
  100.  
  101. find /backup -mtime +7 -delete
  102.  
  103. find /mnt/backup -mtime +7 -delete
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement