| 1 | #!/bin/bash |
| 2 | |
| 3 | # Backs up all files in current directory modified within last 24 hours |
| 4 | #+ in a "tarball" (tarred and gzipped file). |
| 5 | |
| 6 | BACKUPFILE=backup-$(date +%m-%d-%Y) |
| 7 | # Embeds date in backup filename. |
| 8 | # Thanks, Joshua Tschida, for the idea. |
| 9 | archive=${1:-$BACKUPFILE} |
| 10 | # If no backup-archive filename specified on command-line, |
| 11 | #+ it will default to "backup-MM-DD-YYYY.tar.gz." |
| 12 | |
| 13 | tar cvf - `find . -mtime -1 -type f -print` > $archive.tar |
| 14 | gzip $archive.tar |
| 15 | echo "Directory $PWD backed up in archive file \"$archive.tar.gz\"." |
| 16 | |
| 17 | |
| 18 | # Stephane Chazelas points out that the above code will fail |
| 19 | #+ if there are too many files found |
| 20 | #+ or if any filenames contain blank characters. |
| 21 | |
| 22 | # He suggests the following alternatives: |
| 23 | # ------------------------------------------------------------------- |
| 24 | # find . -mtime -1 -type f -print0 | xargs -0 tar rvf "$archive.tar" |
| 25 | # using the GNU version of "find". |
| 26 | |
| 27 | |
| 28 | # find . -mtime -1 -type f -exec tar rvf "$archive.tar" '{}' \; |
| 29 | # portable to other UNIX flavors, but much slower. |
| 30 | # ------------------------------------------------------------------- |
| 31 | |
| 32 | |
| 33 | exit 0 |