您好,登錄后才能下訂單哦!
[root@localhost?mdata]#?cat?mysql_backup.sh #!/bin/bash BACKUP_DIR=/mysql-backup DATE_DIR=`date?+%F` [?-d?$BACKUP_DIR/$DATE_DIR?]?||?mkdir?$BACKUP_DIR/$DATE_DIR?-p?&>/dev/null time="$(date?+"%Y-%m-%d")" USER= PASS= PORT= ? ? #備份數據庫,全量備份 DB_LIST=$(/mdata/mysql/bin/mysql??-u$USER?-p$PASS?-P$PORT?-s?-e?"show?databases;"?2>/dev/null?|egrep?-v?"Database|information_schema|mysql|performance_schema|sys") for?DB?in?$DB_LIST;?do ???if?!?/mdata/mysql/bin/mysqldump?-u$USER?-p$PASS?$DB?>?$BACKUP_DIR/$DATE_DIR/$DB-${time}.sql?2>/dev/null;then ???echo?"$DATE_DIR???$DB-${time}.sql?備份失敗"?>>?/mdata/mysql/mysqlbackup.log ???fi done ? #刪除2天前的備份 DEL_DIR=`date?-d?"-2?days"?+%F` ? [?-d?$BACKUP_DIR/$DEL_DIR?]?&&?rm?-rf?$BACKUP_DIR/$DEL_DIR #加入計劃任務 (echo?"1?01?*?*?*??/mdata/mysql/mysql_backup.sh";crontab?-l)?|crontab
注:我這里是二進制安裝,安裝目錄也可以自己修改為變量,只做參考
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。