服務器備份腳本---每天運行版本

image66925a7507bd1c75.md.png

服務器備份腳本—每天運行版本

腳本內容

#!/bin/bash
# =========================================================
# 請輸入,你想讓備份資料放置到那個獨立的目錄去
basedir=/home/backup/daily/     # 運行前需要自己新建文件夾
                                # 可以自己設置備份目錄

# =========================================================
PATH=/bin:/usr/bin:/sbin:/usr/sbin; export PATH
export LANG=C
basefile1=$basedir/mysql.$(date +%Y-%m-%d).tar.bz2
basefile2=$basedir/cgi-bin.$(date +%Y-%m-%d).tar.bz2
[ ! -d "$basedir" ] && mkdir $basedir

# 1. MysQL (資料庫目錄在 /var/lib/mysql)
cd /var/lib
  tar -jpc -f $basefile1 mysql

# 2. WWW 的 CGI 程式 (如果有使用 CGI 程式的話)
cd /var/www
  tar -jpc -f $basefile2 cgi-bin

使用方法

/etc/crontab 中添加計劃任務

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
20  3   *   *   *   root    yum -y update
20  4   *   *   *   root    /root/bash/backupday.sh
30  4   *   *   0   root    /root/bash/backupwk.sh


文章作者:糖醋魚

版權聲明:轉載請註明來自糖醋魚的博客


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章