LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-21-2009, 01:38 PM   #1
cougar97536
LQ Newbie
 
Registered: Jan 2006
Location: Prospect, Oregon, USA
Distribution: Fedora Core and Mandriva
Posts: 6

Rep: Reputation: 0
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

Last edited by cougar97536; 06-21-2009 at 01:40 PM.
 
Old 06-21-2009, 02:26 PM   #2
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 525

Rep: Reputation: 167Reputation: 167
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`

Last edited by Andy Alt; 06-21-2009 at 02:27 PM. Reason: adding code tags
 
Old 06-21-2009, 03:07 PM   #3
cougar97536
LQ Newbie
 
Registered: Jan 2006
Location: Prospect, Oregon, USA
Distribution: Fedora Core and Mandriva
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-21-2009, 04:37 PM   #4
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 525

Rep: Reputation: 167Reputation: 167
logging cron jobs

Quote:
Originally Posted by cougar97536 View Post
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.
 
Old 06-21-2009, 04:54 PM   #5
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 525

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by cougar97536 View Post
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.
 
Old 06-28-2009, 10:06 PM   #6
cougar97536
LQ Newbie
 
Registered: Jan 2006
Location: Prospect, Oregon, USA
Distribution: Fedora Core and Mandriva
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 06-29-2009, 12:46 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,174

Rep: Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682Reputation: 2682
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.
 
Old 06-29-2009, 02:15 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
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
 
Old 07-09-2009, 04:09 PM   #9
cougar97536
LQ Newbie
 
Registered: Jan 2006
Location: Prospect, Oregon, USA
Distribution: Fedora Core and Mandriva
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
  


Reply

Tags
backup, cron, crontab, date, logfile, logging, rsync, script, scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
regarding backup script ramesh_manu Red Hat 2 02-16-2007 11:01 PM
Need backup script. gtrawoger Linux - Software 2 07-17-2006 07:31 AM
backup script wiltzius Linux - Software 8 03-23-2005 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration