LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Backup Script Help (http://www.linuxquestions.org/questions/linux-newbie-8/backup-script-help-734597/)

cougar97536 06-21-2009 01:38 PM

Backup Script Help
 
hey all, I am Having trouble understanding why my backup script isn't doing its job. I need to copy the files from one directory (the share on my server where all the company files are stored) to another directory, where a backup drive is mounted. I wrote the following script using rsync. the when I run this script from the command line, it shows a list of all the files I need backedup, scrolling across the screen, but doesn't place these files in the backup directory. can anyone see what I did wrong? I also have 6 other scripts just like this one, one for every day of the week. these are supposed to be run by cron. Also is there a way to view what cron has run recently so I can tell if I set that up right?

here is my script:
#!/bin/bash
echo Backup of PSI Files in Progress, please wait...
rsync -avh --delete /PSIFiles /BackupofPSIFiles/autoBackup/monday

thanks for your help in advance,
Christopher

Andy Alkaline 06-21-2009 02:26 PM

rsync will fail if the parent directory isn't already created. There might be an rsync switch for that. But on mine it produces an error message if that happens. Does the directory /BackupofPSIFiles/autoBackup exist yet?

Otherwise I can't see any problem with your syntax.

Instead of having six scripts, you might just want to have one that uses the date command to output the day of the week. Those are backticks around the date command, not apostrophes.

Code:

rsync -avh --delete /PSIFiles /BackupofPSIFiles/autoBackup/`date +%A`

cougar97536 06-21-2009 03:07 PM

thanks for the sugestions
 
The parent directory as well as all of the sub directories ie monday, tuesday, etc. are already created under autobackup I may look into streamlining it and only using one script, but first I need to get the copying working properly.
thanks for the help,
Christopher

Andy Alkaline 06-21-2009 04:37 PM

logging cron jobs
 
Quote:

Originally Posted by cougar97536 (Post 3581550)
Also is there a way to view what cron has run recently so I can tell if I set that up right?

How are you editing your crontab?

This is one way to log it:

Code:

15 21 * * 2,6  /home/andy/bin/gsync_sh >>$HOME/var/log/gsync.log 2>&1
The 2 right angle brackets next to each other tell it to append. A single would overwrite each time.

Andy Alkaline 06-21-2009 04:54 PM

Quote:

Originally Posted by cougar97536 (Post 3581550)
I wrote the following script using rsync. the when I run this script from the command line, it shows a list of all the files I need backedup, scrolling across the screen, but doesn't place these files in the backup directory.

After the scrolling list, there should be output similar to this
Quote:

sent 3.60K bytes received 49 bytes 7.30K bytes/sec
total size is 1.72M speedup is 471.20
Paste the output in a reply.

cougar97536 06-28-2009 10:06 PM

I have mangaged to get some more time to work on this... it seems that the rsync command does what I want, only if I type it into my shell, if it is in a script it just looks at all the directories... copying nothing.
any help fixing this thing would be appreciated, thanks for the help so far
Christopher King

chrism01 06-29-2009 12:46 AM

If its in a script run by cron, be aware that the default env for cron is minimal, especially $PATH. In consequence, std rule is to use complete absolute paths to all cmds and files referenced.

catkin 06-29-2009 02:15 PM

Hello cougar97536 :)

Yes to what chrism01 wrote. If you change the first line of your script to #!/bin/bash -l (that's a letter ell) it will start bash in the same way as when you login.

Best

Charles

cougar97536 07-09-2009 04:09 PM

Thanks for the help. So I have been running the backup command every night manually as follows:
rsync -avh --delete /PSIFiles /BackupofPSIFiles/autoBackup/monday
and it works great. Now if I run a shell script manually that contains the following:
#!/bin/bash -l
echo Backup of PSI Files in Progress, please wait...
rsync -avh --delete /PSIFiles /BackupofPSIFiles/autoBackup/monday

by typing ./test.sh

it seems to be working, scrolling through all the directories, and even gives me a finished message, but nothing changes in the backup directoty, any files that where changed since the last backup still aren't updated.
Till be nice when I figure this out, so I can stop worrying about my data being backed up. thanks again for the help.
Christopher King


All times are GMT -5. The time now is 07:34 AM.