#!/bin/bash
# backup all contents except . and .. in specified
# directory, name related with time
# hoxily@qq.com, 2012-04-19
if [ $# -eq 1 ] #one parameter, it should be a backup directory
then
backupdir=$1
if [ -d "$backupdir" ]
then
cd "$backupdir"
: > /tmp/backuplist #clear list first
for file in * .*
do
if [ "$file" != "." -a "$file" != ".." ] #ignore . and .. directory
then
echo -n "$file " >> /tmp/backuplist
fi
done
backupfilename=`date '+uc_%Y-%m-%d_%H%M.tar.gz'`
tar -zcf $backupfilename `cat /tmp/backuplist`
rm /tmp/backuplist
else
echo "$backupdir is not a directory!"
fi
else
echo "Usage: backup backupdir"
fi
简单的备份用bash脚本
最新推荐文章于 2020-03-27 18:54:28 发布