| Post Title | Posted | Description |
|---|---|---|
Parent Directory
|
||
| Nightly File Backup | 2007-02-11 15:03 | In a fashion similar to how I described nightly mysql backup, you can also do nightly file backup. |
In a fashion similar to how I described nightly mysql backup, you can also do nightly file backup. In this particular example, I used tar with gzip compression because I like to keep the last 7 backups of a website. If I was looking for a script that just backs up one location to another, using rsync with publick key authentication would have been more appropriate and I might talk about that in another post.
As with majority of my posts, I offer nothing new or unique. This is just a script that has been useful to me and if you find it useful, my time and effort in writing this up have been validated.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<code>
#!/bin/sh
#Define your variables here:
SOURCE_DIR= # e.g. /home/andrej/documents
TARGET_DIR= # e.g. /mnt/hda7/docbackups
BACKUP_FILENAME= # e.g. andrejdocs
# Make sure output directory exists.
if [ ! -d $TARGET_DIR ]; then
mkdir -p $TARGET_DIR
fi
# Rotate backups
for j in 6 5 4 3 2 1 0; do
for i in $TARGET_DIR/$BACKUP_FILENAME.tgz.$j; do
if [ -e $i ]; then
mv $i ${i/.$j/}.$(( $j + 1 ));
fi
done
done
cd $SOURCE_DIR
tar -cvzf $TARGET_DIR/$BACKUP_FILENAME.tgz.0 *
chmod 600 $TARGET_DIR/$BACKUP_FILENAME.tgz.0
</code> |
In the Nightly MySQL Backup I briefly talk about how to use cron in scheduling scripts to run periodically.
This website is powered by Wordpress
Leave a Comment