簡體   English   中英

在ubuntu中為MySQL數據庫設置自動備份

[英]Automatic backup set in ubuntu for mysql database

我目前正在使用ubuntu 16.04 LTS。 在我的/etc/crontab我為mysql數據庫備份添加了一些腳本。

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
 17 *  *   *   *  root  cd / && run-parts --report /etc/cron.hourly
 25 6  *   *   *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
 47 6  *   *   7  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
 52 6  1   *   *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

# this is my custom script for database backup daily
15 2   *   *   *  root  /opt/lampp/bin/mysqldump -u root database_name > /home/backup_$(date +%Y%m%d).sql 
#

當我從終端運行它時,它運行完美。 它應該每天2:15 AM備份我的數據庫,但是它沒有執行crontab的任何操作。

我遇到了這個問題,通常與cron環境變量有關。 由於cron不是shell用戶,因此它具有與控制台用戶不同的環境變量。 您可以通過同時對cron和您的用戶運行這樣的內容進行比較:

usr/bin/env | sort > /tmp/cronEnv.out

這將允許您比較兩個輸出。 如果我必須打賭,它應該是諸如時區,語言或二進制文件之類的,由於PATH不同而無法找到。 也請在此處發布cron日志,以防萬一。 取決於dristro,通常可以在這里找到它們:

/var/log/cron //could also be syslog or something else.

這里有一篇關於它的文章

與您的問題沒有直接關系:我還為Mysql和其他內容編寫了一個備份腳本,仍在開發中,但是可以為您的環境工作,到目前為止僅使用了50或60台服務器,但是您可以嘗試使用如果需要幫助,請ping我。

除了這可能還有其他問題,但是如果腳本可以正常運行,則出於某些原因環境應該有所不同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM