备份ubuntu网站任务(Crontab)

技术分享 Story 78浏览 0评论
摘要

备份ubuntu网站任务(Crontab)

使用Crontab和寫一個sript

建立一個script

vi /data/backup/weekly.sh

內容如下

#!/bin/bash
#
# This program is created by hdj 2004/02/03
#
# What is this program?
# This program will backup the following messages:
# 1. mysql data (/var/lib/mysql);
# 2. www( /var/www/ )
#
# HOW TO RUN THIS PROGRAM?
# Just put the file into /etc/crontab job,
# or put this file's link file to /etc/cron.weekly!
# or modify the /etc/crontab
back=/data/backup/www_backup
tar -zcf $back/mysql.tar.gz /var/lib/mysql
tar -zcf $back/www.tar.gz /var/www

==============================================================

再修改/etc/crontab

# /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.
# This file also has a username field, 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
25 6 * * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6 * * 7 root test -e /usr/sbin/anacron || run-parts --report /etc/cron.weekly
52 6 1 * * root test -e /usr/sbin/anacron || run-parts --report /etc/cron.monthly
#

45 20 * * 1 root /data/backup/weekly.sh <==加入這行

转载请注明:成长的对话 » 备份ubuntu网站任务(Crontab)