Help with bash script

Red Squirrel

No Lifer
May 24, 2003
71,312
14,084
126
www.anyf.ca
I have this bash script for bakups that's really not co-operating and I can't seem to find the issue. Here is the scenario:

I have a /backup partition and a /data partition.

This script takes firls from /data/ and puts it in /backup/data/[weekday]_daily.

This part works fine. I use date +%a to get the day name.

Now I also have a /backup/data/master symlink that is generated to point to the folder of the day the backup runs. This way when my other server grabs the backup it's the latest, as it backs up from this folder.

It also puts a file called date.txt in the [weekday]_daily folder just so I can check that the backup DID run.

Now this is where it gets funny. At random, it will create a date.txt~ file. I never told it to do this, it should only be creating a date.txt file. Also, at random it will create a randomly named symlink inside the [weekday]_daily folder. For example, sometimes it will call it [weekday]_daily othertimes [weekday]_daily~. I this case the weekday is actually the previous day.


Here is the script:


sourcepath="/data/"

subfolder="`date +%a`_daily/"

pathname="/backup/data/"

mkdir -p ${pathname} > /dev/null

#backup start
echo "starting backup from ${sourcepath} to ${pathname} + ${subfolder}"

rsync -vrbu --delete-after --force ${sourcepath} ${pathname}${subfolder}

date > ${pathname}${subfolder}date.txt

echo setting permissions and ownership...
chown -R backup_admin:backup_admin ${pathname}${subfolder}
chmod -R 500 ${pathname}${subfolder}

rm -f ${pathname}master
ln -s ${pathname}${subfolder} ${pathname}maste



Maybe another set of eyes can spot the problem.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
From rsync --help:

-b, --backup make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX set backup suffix (default ~ w/o --backup-dir)

So rsync with -b on file will create file~ if overwriting it.
 

Red Squirrel

No Lifer
May 24, 2003
71,312
14,084
126
www.anyf.ca
Oh I thought it meant to perform a backup from the source. That explains the first problem then. Just not sure why it's creating symlinks in the wrong place now.

Edit: actually removing "b" seems to have fixed the symlink thing too. Thanks.