linux-bash 归档数据文件
来源:互联网 发布:mac 未能存储文稿 编辑:程序博客网 时间:2024/06/09 23:59
Source: <<Linux 命令行与Shell脚本编程大全>>
如何使用shell备份linux系统上的数据
归档数据文件
1. 你需要归档的文件或目录 Files_To_Backup
/home/winnie/Downloads
/home/winnie/Documents
/home/winnie/script
/home/winnie/Does_not_exist
2.创建按日归档的脚本 Daily_Archive
#!/bin/bash##Daily_Archive-Archive designated files & directories#############################Gather Current Date#DATE=`date +%y%m%d`##Set Archieve File Name#FILE=archieve$DATE.tar.gz##Set Configuration and Destination File#CONFIG_FILE=/home/winnie/archive/File_To_BackupDESTINATION=/home/winnie/archive/$FILE########Main Script################Check Backup Config file exists#if [ -f $CONFIG_FILE ]#Make sure the config file still existsthen#If it exists, do nothing but continue on.echoelse#If it doesn't exist, issue error&exit script.echoecho "$CONFIG_FILE does not exist."echo "Backup not completed due to missing Configuration File"echoexitfi##Build the names of all the files to backup#FILE_NO=1#Start on Line 1 of Config File.exec < $CONFIG_FILE#Redirect Std Input to name of Config File#read FILE_NAME#Read 1st record#while [ $? -eq 0 ] #Create list of files to backupdo#Make sure the file or directory existsif [ -f $FILE_NAME -o -d $FILE_NAME ]then#If file exists, add its name to the list.FILE_LIST="$FILE_LIST $FILE_NAME"else#If file doesn't exist, issue warningecho echo "$FILE_NAME does not exist."echo "Obviously, I will not include it in this archive."echo "It is listed on line $LINE_NO of the config file."echo "Continuing to build archive list.."echofi#FILE_NO=$[ $FILE_NO + 1 ] #Increasing Line/File number by one.read FILE_NAME#Read next recor.done################################Backup the files and compress archive#tar -czf $DESTINATION $FILE_LIST 2> /dev/null#
运行结果sh ./Daily_Archive
/home/winnie/Does_not_exist does not exist.
Obviously, I will not include it in this archive.
It is listed on line of the config file.
Continuing to build archive list..
winnie@ubuntu:~/archive$ ls -al
total 20
drwxr-xr-x 3 root root 4096 Jul 17 06:02 .
drwxr-xr-x 18 winnie winnie 4096 Jul 17 05:42 ..
-rw-r--r-- 1 root root 3359 Jul 17 05:59 archieve170717.tar.gz
-rw-r--r-- 1 root root 94 Jul 17 05:42 File_To_Backup
drwxr-xr-x 3 root root 4096 Jul 17 06:02 home
winnie@ubuntu:~/archive$ sudo tar -zxvf archieve170717.tar.gz
[sudo] password for winnie:
home/winnie/Downloads/
home/winnie/Documents/
home/winnie/script/
home/winnie/script/mytest1
home/winnie/script/Delete_User
home/winnie/script/test10
home/winnie/script/Big_user
home/winnie/script/Daily_Archive
=======================================================================================建立Hourly_Archive
#!/bin/bash
#
#Hourly_Archive-Every hour create an archive
##########################################
#
#Set Configuration file
#
CONFIG_FILE=/home/winnie/archive/hourly/Files_To_Backup
#
#Set Base archive destination location
#
BASEDEST=/home/winnie/archive/hourly
#
#Gather Current Day. Month&Time
#
DAY=`date +%d`
MONTH=`date +%m`
TIME=`date +%k%M`
#
#Create archive destination directory
#
mkdir -p $BASEDEST/$MONTH/$Day
#
#Buid archive destination file name
#
DESTINATION=$BASEDEST/$MONTH/$Day/archive$TIME.tar.gz
##############Main script##################
- linux-bash 归档数据文件
- 利用归档恢复数据文件
- 归档与非归档模式下更改数据文件位置
- 用归档日志恢复丢失的数据文件
- rman 恢复---归档丢失and数据文件损坏
- 非归档模式下恢复数据文件浅析
- 非归档数据文件offline的恢复
- 非归档数据文件offline drop处理
- 非归档模式下数据文件移动方法
- 误删除数据文件-无归档处理方法
- 归档模式下-丢失非关键数据文件
- 归档模式下-丢失关键数据文件
- linux bash
- Linux Bash
- linux bash
- Linux -- bash
- linux bash
- Linux bash
- 09读书笔记之提升ListView的运行效率
- 七月的无奈
- 记忆化搜索:POJ1088-滑雪(经典的记忆化搜索)
- git reset简介
- java实现简单链表
- linux-bash 归档数据文件
- 重新装修了博客
- POJ 1466 Girls and Boys(二分图最大独立集)
- python控制流-2017-7-18
- hdu 3440 House Man (去绝对值构图差分约束)
- 使用Endpoint(端点)类发布webservice
- 第3部分 装载与动态链接---(6)可执行文件的装载与进程
- 用matlab怎么画图,比如y =exp(x^2)?
- 欢迎使用CSDN-markdown编辑器