Linux Web directory file full script

Source: Internet
Author: User


#!/bin/bash
#文件全备脚本
#删除7天以前的文件
#调用方法
#yxy
#www. sql8.net
#[email protected]
#2014-08-20
#请主意所有路径都为全整目录
#sh filebak.sh The number of days to keep files for the destination directory backup file to be backed up
#sh Filebak.sh/home/wd/wd/wd/home/wd/wd/bakup 7
#sh Filebak.sh/home/dd/dd/dd/home/dd/dd/bakup 7


#path
Path=$1
Backuppath=$2
N=$3




#参数不全
If ["$path" = = ""] | | ["$backupPath" = = ""] | | ["$n" = = ""]; Then
echo "Insufficient arguments"
Exit 1
Fi


#目标目录不存, exit
if [!-D "$path"]; Then
echo "Directory does not exist"
Exit 1
Fi




#如果存放备份文件的目录不存, New
if [!-D "$backupPath"]; Then
mkdir "$backupPath"
Fi


#Time Information
#时间
Time= ' date + '%y-%m-%d-%h-%m-%s '
day= ' date + '%d '
Month= ' date + '%y-%m '
weekday= ' date + '%u '


#路径最后一个目录
Foldername= ' basename $path '
Filename= $folderName $day$time.tar.gz


#如果文件存在, deleting
If [-E "$fileName"]; Then
RM-RF $fileName
Fi


CD $path
Cd..
TAR-ZCF $fileName $folderName


#移动备份文件到备份目录
MV $fileName $backupPath





#删除N天前的数据
Find $backupPath-name "$folderName *.gz"-type f-mtime + $n-exec rm {} \;



Crontab setting **********************************************
Set the relevant backup rules as needed, some of the rules here


#每天1点备份
0 1 * * * cd/opt/backup/database &&/1.sh




#每周一1点备份
0 1 * * 1 cd/opt/backup/database &&/1.sh




#每2小时备份
0 */2 * * * cd/opt/backup/database &&/1.sh




#每2天备份
0 0 */2 * * cd/opt/backup/database &&/1.sh


#每个月5号1点20分备份
1 5 * * Cd/opt/backup/database &&/1.sh




For more Contrab rules please see
Http://www.sql8.net/a/course/caozuoxitong/liunx/2014/0815/30328.html





MySQL Full script upgrade, support multiple hosts, multiple databases http://www.sql8.net/a/course/caozuoxitong/liunx/2014/0820/30545.html
Mysql fully prepared script, this script can back up multiple databases: http://www.sql8.net/a/course/shujuku/Mysql/2014/0815/30340.html



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.