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.
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.
