cron.hourly jobs

i want to create a simple script to backup using rsync a folder on PC1
(suse 11) to PC2 (Windows XP) which can then be put into cron.hourly or
cron.daily.

The target folder is mounted by a fstab entry:-

Code:

//192.168.1.226/backup /home/badger_fruit/lan/backup cifs username=badger_fruit,password=mypassword,auto,uid=badger_fruit,gid=users,_netdev 0 0


By using the command …

Code:

rsync -avz /home/badger_fruit/data/photos/ /home/badger_fruit/lan/backup/


… it creates the files/folders/subfolders etc as expected (hoorah)
BUT i get a message saying there was an error:-

Code:

bgrsvr-y:/etc/cron.hourly # rsync -avz /home/badger_fruit/data/photos/ /home/badger_fruit/lan/backup/

sending incremental file list
./
rsync: failed to set times on “/home/badger_fruit/lan/backup/.”: Permission denied (13)
Aquarium/
CapeVerde/
Christmas2008/
Computers/
GardenProject/
LoftProject/
Misc/
School Photos/

sent 4175 bytes received 47 bytes 8444.00 bytes/sec
total size is 41067045 speedup is 9726.92
rsync error: some files could not be transferred (code 23) at main.c(1031) [sender=3.0.2]
bgrsvr-y:/etc/cron.hourly #


I have checked that “everyone” has “full control” on the Windows share
and that the folder is not in “read only” mode.

The username and password provided in the fstab are also correct, if i
do a manual cp, it will work without any such error.

Any ideas from anyone please?


badger_fruit

badger_fruit’s Profile: http://forums.opensuse.org/member.php?userid=2099
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Hi
Try running it as your user (create your own crontab), rather than root,
that will ensure you keep ownership of the files.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-4-default
up 1 day 4:52, 3 users, load average: 0.07, 0.29, 0.49
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82

malcolmlewis;1907689 Wrote:
> Hi
> Try running it as your user (create your own crontab), rather than
> root, that will ensure you keep ownership of the files.

an excellent idea, unfortunately, im a noob so don’t know how :frowning:
there are only two users on the “source” pc, root and “badger_fruit”,
would i just change the ownership of the “/etc/cron.hourly/backup” file
or move it somewhere else on the filesystem?

(ps, sorry, im such a noob lol!)


badger_fruit

badger_fruit’s Profile: http://forums.opensuse.org/member.php?userid=2099
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Stuff in cron.hourly is always executed as root.

If you want to run as some account, or even if you don’t, you should
put jobs in /etc/cron.d, because that separates it from the system jobs
and it’s easier to see that it should be retained across upgrades. The
format is:

> min hour day month weekday user command

e.g. a file /etc/cron.d/backupjob

> 2 2 * * * root /root/bin/dobackup

Every morning at 0202, run /root/bin/dobackup as root

To run as a different user, change the user field. But test that the
user can indeed run the command. And remember that some environment
variables will not be set, like $HOME, $DISPLAY, etc.


ken_yap

ken_yap’s Profile: http://forums.opensuse.org/member.php?userid=221
View this thread: http://forums.opensuse.org/showthread.php?t=401642

thanks
so to clarify

if i create a simple text file in /home/badger_fruit/data, chown it to
use badger_fruit

called “backupfiles”, contents are:-

Code:

#!/bin/sh
rsync -avz /home/badger_fruit/data/photos/ /home/badger_fruit/lan/backup/


chmod it to make it executable (eg chmod 555 backup)
then create a job in cron.d, called “runbackup”

the contents being:-

Code:

1 * * * * badger_fruit /home/badger_fruit/data/backupfiles


that would work?
(ie run at 01:00hrs every day as badger_fruit)

how would i know this had run? would it dump output to
/var/log/messages, or some other place?

by the way, i ran it as badger_fruit and it “worked”, well, it gave the
same error messages but didn’t complain about no permission to run this
blah blah


badger_fruit

badger_fruit’s Profile: http://forums.opensuse.org/member.php?userid=2099
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Actually at 1 minute past every hour.

Output from the program, if any, gets mailed to the user specified. You
can also divert it yourself.

Code:

1 * * * * badger_fruit /home/badger_fruit/data/backupfiles > /tmp/backup.log 2>&1

The 2>&1 merges stderr output to stdout.


ken_yap

ken_yap’s Profile: http://forums.opensuse.org/member.php?userid=221
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Hi
Also remember to use the full path to rsync eg /usr/bin/rsync or use
the path statement at the begining.

I always use my own crontab for stuff like this, just run crontab -e to
create one. There are also some GUI tools for it as well, depends on
your desktop.


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-4-default
up 1 day 6:50, 4 users, load average: 0.02, 0.07, 0.13
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82

ken_yap;1907722 Wrote:
> Actually at 1 minute past every hour.

ah har, that’s actually better for me, they are family photos and after
my recent disaster i need to ensure i have a good mirror!

ken_yap;1907722 Wrote:
>
> Output from the program, if any, gets mailed to the user specified. You
> can also divert it yourself.
>
> >
Code:

> > 1 * * * * badger_fruit /home/badger_fruit/data/backupfiles > /tmp/backup.log 2>&1

> >
>
> The 2>&1 merges stderr output to stdout.

your code sample above, would that just dump the messages from the
program output into a file and then append each time it’s run? because
that is also fine, i can tail it if i want or open in
nano/more/less/whatever.


badger_fruit

badger_fruit’s Profile: http://forums.opensuse.org/member.php?userid=2099
View this thread: http://forums.opensuse.org/showthread.php?t=401642

well i tried it, i set it up to run 15 minutes past the hour each hour
and it did work but didn’t dump the output to a text file, it seemed to
mail it to root; a few moments after it ran (and it did run, hoorah!) i
was told “new mail in /var/mail/root”

opened it and saw the output.

is it possible to dump output into a file instead of mail?
edit- i also saw i still got the same permission error, despite running
as badger_fruit :frowning:


badger_fruit

badger_fruit’s Profile: http://forums.opensuse.org/member.php?userid=2099
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Yes, the way I showed you. It should have been mailed to badger_fruit
anyway so maybe you had not written out your changes or something else
went wrong. If you want to append, change the > to >>.


ken_yap

ken_yap’s Profile: http://forums.opensuse.org/member.php?userid=221
View this thread: http://forums.opensuse.org/showthread.php?t=401642

Hi
Look at the man page for rsync, there are lots of options. Here is a
snippet I use;


FILENAME=/tmp/backup.`date +\%s`
/usr/bin/rsync -rlLtuzi --stats --progress --delete \
/home/malcolml/* /media/laptop_backup/opensuse/ \
> $FILENAME
/usr/bin/tr -d '\015' < $FILENAME | /usr/bin/mailx -s 'HOME Backup via
RSYNC to USB Disk' malcolml@localhost
# Delete backup file
rm $FILENAME


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-4-default
up 1 day 7:20, 4 users, load average: 0.13, 0.08, 0.09
GPU GeForce 6600 TE/6200 TE - Driver Version: 177.82