LDP/LDP/guide/docbook/abs-guide/ex58.sh

34 lines
1.1 KiB
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2002-06-03 14:35:48 +00:00
# Backs up all files in current directory modified within last 24 hours
#+ in a "tarball" (tarred and gzipped file).
2001-07-10 14:25:50 +00:00
2004-01-05 13:20:57 +00:00
BACKUPFILE=backup-$(date +%m-%d-%Y)
# Embeds date in backup filename.
# Thanks, Joshua Tschida, for the idea.
2002-07-22 15:11:51 +00:00
archive=${1:-$BACKUPFILE}
2008-11-23 22:43:47 +00:00
# If no backup-archive filename specified on command-line,
2004-01-05 13:20:57 +00:00
#+ it will default to "backup-MM-DD-YYYY.tar.gz."
2001-09-04 13:27:31 +00:00
2002-07-22 15:11:51 +00:00
tar cvf - `find . -mtime -1 -type f -print` > $archive.tar
gzip $archive.tar
echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"."
2001-07-10 14:25:50 +00:00
2002-06-03 14:35:48 +00:00
# Stephane Chazelas points out that the above code will fail
#+ if there are too many files found
#+ or if any filenames contain blank characters.
2001-07-10 14:25:50 +00:00
# He suggests the following alternatives:
2002-07-22 15:11:51 +00:00
# -------------------------------------------------------------------
# find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar"
2001-07-10 14:25:50 +00:00
# using the GNU version of "find".
2002-06-03 14:35:48 +00:00
2002-07-22 15:11:51 +00:00
# find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \;
# portable to other UNIX flavors, but much slower.
# -------------------------------------------------------------------
2001-07-10 14:25:50 +00:00
exit 0