daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Sep 26th, 2016 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # 备份脚本 - Dropbox版
  3. #
  4. # 数据库备份无效请设置 mysqldump 为绝对路径
  5. #
  6. # tar dropbox mysqldump
  7. #
  8. # name backup_linode.sh
  9. # verson 2.0
  10. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
  11.  
  12. # 需要保存的服务器文件夹,可以用空格隔开多个文件夹
  13. BACKUP_SRC="/data/wwwroot"
  14.  
  15. # 指定 dropbox_uploader.sh 脚本的保存目录
  16. SCRIPT_DIR="/root/shell"
  17.  
  18. # 上传到 DropBox 的文件夹
  19. DROPBOX_DIR="/linode/backup"
  20.  
  21. # 服务器上临时的备份保存文件夹
  22. LOCAL_BAK_DIR="/data/backup/upload"
  23.  
  24. # 日志
  25. LOG_DIR="/data/backup/backup.log"
  26.  
  27. # MySQL 相应配置, 修改 mysqldump 配置文件,可忽略此项配置
  28. MYSQL_SERVER="localhost"
  29. MYSQL_USER="root"
  30. MYSQL_PASS="password"
  31.  
  32. # 数据备份压缩后的文件名称
  33. DBBakName=Data_$(date +"%Y%m%d").tgz
  34. WebBakName=Web_$(date +"%Y%m%d").tgz
  35.  
  36. # 已过期备份数据的名称(3天前的数据会被删除)
  37. OldDBBakName=Data_$(date -d -3day +"%Y%m%d").tgz
  38. OldWebBakName=Web_$(date -d -3day +"%Y%m%d").tgz
  39.  
  40. # 导出 MySQL 数据库备份(所有数据库),并压缩为指定文件名,mysqldump 无效请设置为绝对路径
  41. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Database backup" >> $LOG_DIR
  42. /usr/local/mysql/bin/mysqldump --events --all-databases > $LOCAL_BAK_DIR/Database.sql
  43. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Database zip" >> $LOG_DIR
  44. tar czvPf $LOCAL_BAK_DIR/$DBBakName $LOCAL_BAK_DIR/Database.sql && rm -rf $LOCAL_BAK_DIR/Database.sql
  45.  
  46. # 压缩需要保存的文件夹为指定文件名
  47. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Web backup" >> $LOG_DIR
  48. tar czvPf $LOCAL_BAK_DIR/$WebBakName $BACKUP_SRC
  49.  
  50. # 上传压缩后的备份文件到指定的 DropBox 目录
  51. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Upload start" >> $LOG_DIR
  52. $SCRIPT_DIR/dropbox_uploader.sh upload $LOCAL_BAK_DIR/$DBBakName $DROPBOX_DIR/$DBBakName
  53. $SCRIPT_DIR/dropbox_uploader.sh upload $LOCAL_BAK_DIR/$WebBakName $DROPBOX_DIR/$WebBakName
  54. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Upload done" >> $LOG_DIR
  55.  
  56. # 上传完成后删除服务器上及DropBox中已经过期的备份数据,节省空间
  57. echo $(date +"[%Y-%m-%d %H:%M:%S]")" delete old backup start" >> $LOG_DIR
  58.  
  59. echo $(date +"[%Y-%m-%d %H:%M:%S]")" delete "$OldDBBakName >> $LOG_DIR
  60. rm -f $LOCAL_BAK_DIR/$OldDBBakName
  61. $SCRIPT_DIR/dropbox_uploader.sh delete $DROPBOX_DIR/$OldDBBakName
  62.  
  63. echo $(date +"[%Y-%m-%d %H:%M:%S]")" delete "$OldWebBakName >> $LOG_DIR
  64. rm -f $LOCAL_BAK_DIR/$OldWebBakName
  65. $SCRIPT_DIR/dropbox_uploader.sh delete $DROPBOX_DIR/$OldWebBakName
  66.  
  67. echo $(date +"[%Y-%m-%d %H:%M:%S]")" delete old backup done" >> $LOG_DIR
  68. echo $(date +"[%Y-%m-%d %H:%M:%S]")" Todady backup done" >> $LOG_DIR
  69. echo "=======" >> $LOG_DIR
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top