每天定时备份我的网站数据

######################每天定时备份我的网站数据

[root@bj-02-dev cron.daily]# more wpback.sh

!/bin/bash

DATE=”date +%Y%m%d

HOUR=”date +%H

BACKUPDEST=/data/

DATE=date +%y%m%d%H
#

Set Archive File Name

#

FILEMYSQL=MYSQLarchive$DATE.tar.gz
FILEWP=WParchive$DATE.tar.gz
#

Set Configuration and Destination File

SOURCE_FILEMYSQL=/var/lib/docker/volumes/wordpress_mysql
SOURCE_FILEWP=/var/lib/docker/volumes/wordpress_wordpress

DESTINATIONMYSQL=/data/$DATE/$FILEMYSQL
DESTINATIONWP=/data/$DATE/$FILEWP

DIR=”/data/${DATE}”

DELAY=86400

COUNT=365

if ! test -d ${DIR}
then
/bin/mkdir -p ${DIR}
fi

tar -czf $DESTINATIONMYSQL $SOURCE_FILEMYSQL 2> /dev/null &
tar -czf $DESTINATIONWP $SOURCE_FILEWP 2> /dev/null &
#

[root@bj-02-dev cron.daily]#

定时任务:

[root@bj-02-dev cron.daily]# vim /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

02 4 * * * root run-parts /etc/cron.daily

Leave a Reply

Your email address will not be published. Required fields are marked *