#!/bin/bash
#backup.sh
BACKUPFILE=backup-`date +"%F"`#在备份文件中嵌入时间.
echo `date +"%F"`
echo $BACKUPFILE
archive=${1:-$BACKUPFILE} # 如果在命令行中没有指定备份文件的文件名,
#+ 那么将默认使用"backup-MM-DD-YYYY.tar.gz".
#if [ -z $1 ] # then # archive=$BACKUPFILE #else # archive=$1.tar.gz #fi tar cvf - `find . -mtime -1 -type f -print` > $archive.tar gzip $archive.tar
echo $archive.tar
echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."
exit 0
===测试结果==
root@client.example.com ~/yang # ./backup.sh lizhe
2011-03-14
backup-2011-03-14
./showcol.sh
./.swp
./read.sh
./password.sh
./backup.sh
./getPro.sh
./showcolor.sh
./length.sh
./background-loop.sh
./backup-2011-03-14.tar.gz
./yang.tar.gz
lizhe.tar
Directory /root/yang backed up in archive file "lizhe.tar.gz".
不带参数 root@client.example.com ~/yang #
./backup.sh 2011-03-14
backup-2011-03-14
./showcol.sh
./.swp
./read.sh
./password.sh
./backup.sh
./getPro.sh
./showcolor.sh
./length.sh
./background-loop.sh
./yang.tar.gz
backup-2011-03-14.tar Directory /root/yang backed up in archive file "backup-2011-03-14.tar.gz". root@client.example.com ~/yang # ls
1.txt background-loop.sh b.txt length.sh read.sh test.txt yang.tar.gz
a
backup-2011-03-14.tar.gz getPro.sh
lizhe.tar.gz showcolor.sh today.backup
a.txt backup.sh io.sh password.sh showcol.sh today.txt