cazz
July 22nd, 2007, 02:53 PM
Hi
I try to create my first bash script and that is a backup script that use rsync
That maybe dont look so good and maybe someone have any tips to give me to make my backup script better then just write :)
The code look like this
#!/bin/bash
SOURCE=/from/a/directory/
TARGET=/to/a/directory/
DATE=`date +'%m-%d-%Y'`
CHANGE=/to/a/directory/temp/
OLDBACKUP=/to/a/directory/old/
rsync -az $SOURCE $TARGET -b --backup-dir=$CHANGE
if test -a /to/a/directory/old/*
then
tar -cvvf $OLDBACKUP$DATE.tar $CHANGE
rm $OLDBACKUP*
fi
I going to create a backup script that run every night and see if that have change from a directory and if it have it going update my backupfile and take the old file and compress it to a file that have the date on.
So I can go back if I have write something or mistake delete some file.
Now to my problem
I have try so I have in the if file
if test -a $CHANGE*
but that give me a error "too many arguments" at line 11
I try to create my first bash script and that is a backup script that use rsync
That maybe dont look so good and maybe someone have any tips to give me to make my backup script better then just write :)
The code look like this
#!/bin/bash
SOURCE=/from/a/directory/
TARGET=/to/a/directory/
DATE=`date +'%m-%d-%Y'`
CHANGE=/to/a/directory/temp/
OLDBACKUP=/to/a/directory/old/
rsync -az $SOURCE $TARGET -b --backup-dir=$CHANGE
if test -a /to/a/directory/old/*
then
tar -cvvf $OLDBACKUP$DATE.tar $CHANGE
rm $OLDBACKUP*
fi
I going to create a backup script that run every night and see if that have change from a directory and if it have it going update my backupfile and take the old file and compress it to a file that have the date on.
So I can go back if I have write something or mistake delete some file.
Now to my problem
I have try so I have in the if file
if test -a $CHANGE*
but that give me a error "too many arguments" at line 11