USA Linux Users Group Forum Index
Log in Register FAQ Memberlist Search USA Linux Users Group Forum Index Album

Rsync cron job not syncing

 
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Servers and Server Administration
View previous topic :: View next topic  
Author Message
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sat Sep 27, 2024 7:36 am    Post subject: Rsync cron job not syncing Reply with quote

Hi everyone, been a while since I was here last. Smile

I am running a DNS-323 NAS box with fun_plug installed, trying to get it to automate backups. The script runs fine if I run it manually so paths are all fine, but the cron job writes to the named text file but doesn't run any syncs. Anyone tell me what I am doing wrong?

Called script scripy file
Quote:
cd /
rsync -avz /mnt/HD_a2/COMPINFO/ /mnt/HD_b2/COMPINFO_bak
echo 'COMPINFO backed up' `date` >> /mnt/HD_a2/COMPINFO/dlink/backuplog.txt
rsync -avz /mnt/HD_a2/GAMES/ /mnt/HD_b2/GAMES_bak
echo 'GAMES backed up' `date` >> /mnt/HD_a2/COMPINFO/dlink/backuplog.txt
rsync -avz /mnt/HD_a2/NETDOCS/ /mnt/HD_b2/NETDOCS_bak
echo 'NETDOCS backed up' `date` >> /mnt/HD_a2/COMPINFO/dlink/backuplog.txt
rsync -avz /mnt/HD_a2/'Work Files'/ /mnt/HD_b2/'Work Files_bak'
echo 'Work Files backed up' `date` >> /mnt/HD_a2/COMPINFO/dlink/backuplog.txt


Script to write cron entry:
Quote:

CRONTXT=/mnt/HD_a2/crontab.txt

# start with existing crontab
/bin/crontab -l > $CRONTXT

# add the Rsync shell script to cron
/bin/echo "0 3 * * * /mnt/HD_a2/sync_backup.sh

/mnt/HD_a2/fun_plug.d/log/rsync.last.log 2>&1" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT


Thanks
Mick


Back to top
View user's profile Send private message
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sat Sep 27, 2024 9:59 am    Post subject: Reply with quote

Ok, the main problem seems to be that it won't write to the file "crontab.txt" Yet this is what the instructions says here. Have found some other errors in the script, but even fixing them fails to get the file created with the name crontab.txt. Any ideas?

Thanks
Mick



_________________
Kubuntu
Back to top
View user's profile Send private message
pbharris
Member


Joined: 02 Jul 2024
Posts: 320
Location: chicago

PostPosted: Sat Sep 27, 2024 3:28 pm    Post subject: Reply with quote

hello,
assuming the paths are good:
Code:

CRONTXT=/mnt/HD_a2/crontab.txt

# start with existing crontab
/bin/crontab -l > $CRONTXT

# add the Rsync shell script to cron
/bin/echo "0 3 * * * /mnt/HD_a2/sync_backup.sh \
/mnt/HD_a2/fun_plug.d/log/rsync.last.log 2>&1" >> $CRONTXT

# install the new crontab
/bin/crontab $CRONTXT

# clean up
/bin/rm $CRONTXT


Do you get any output from the command /mnt/HD_a2/sync_backup.sh /mnt/HD_a2/fun_plug.d/log/rsync.last.log



_________________
Fedora
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sat Sep 27, 2024 11:12 pm    Post subject: Reply with quote

Actually that path was one of the errors: /mnt/HD_a2/fun_plug.d dies not exist in this version.

Have realised I may be trying to run as root, so have changed the commands to run directly and added the rsync from the fun_plug bin instead of /bin, thus:
Quote:

#!/bin/sh
CRONTXT=/mnt/HD_a2/crontab.txt
# start with existing crontab
/bin/crontab -l > $CRONTXT
# add the 2 Rsync shell scripts to cron
/bin/echo "15 9 * * * /mnt/HD_a2/ffp/bin/rsync -rlptDv --delete /mnt/HD_a2 /mnt/HD_b2 >/mnt/HD_a2/ffp/log/rsync.last.log 2>&1" >> $CRONTXT
/bin/echo "0 2 * * mon /mnt/HD_a2/fun_plug.d/bin/rsync -rlptDv --delete /mnt/HD_a2 /mnt/ext >/mnt/HD_a2/fun_plug.d/log/rsync.last.log 2>&1" >> $CRONTXT
# install the new crontab
/bin/crontab $CRONTXT
# clean up
/bin/rm $CRONTXT
Gonna see if it will run this morning for me.... keep you posted.

Thanks
Mick



_________________
Kubuntu
Back to top
View user's profile Send private message
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sun Sep 28, 2024 7:50 am    Post subject: Reply with quote

Ok, it is not writing to crontab. says the file /mnt/HD_a2/crontab.txt does not exist (actually says No such file or directory2/crontab.txt) - is there a problem with having the _a in the path?? Do I need quotes or something?

Thanks
Mick



_________________
Kubuntu
Back to top
View user's profile Send private message
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Thu Oct 02, 2024 10:51 pm    Post subject: Reply with quote

Path looks fine to me. Underscores are fine in Linux directory and file names. Question stands, does the file / path exist? If you:
Code:
cat /mnt/HD_a2/crontab.txt

from the command line, do you get any output, or does cat complain that the file doesn't exist as well?



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Fri Oct 03, 2024 9:25 am    Post subject: Reply with quote

OK, the file exists. It.s currently empty, so cat reports " ". But running editcron.sh still gives error: No such file or directory2/crontb Crying or Very sad

Obviously the script is not parsing the filename correctly, but why???? Confused Any ideas, you *nix gurus out there?

Thanks
Mick



_________________
Kubuntu
Back to top
View user's profile Send private message
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Fri Oct 03, 2024 2:51 pm    Post subject: Reply with quote

You might try adding
Code:
tee -a /mnt/HD_a2/COMPINFO/dlink/backuplog.txt

to the rsync lines of your script to see if rsync is spitting up any errors while running as a cron job.

I recall that the environment for cron is different than your login environment, and I think that this can have an impact on scripts that seem to work just fine when run from the console.



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
mushroom
Ultimate Member


Joined: 29 Jun 2024
Posts: 2128
Location: Queen Charlotte B. C. Canada

PostPosted: Fri Oct 03, 2024 4:36 pm    Post subject: Reply with quote

I remember having an issue with a cronjob a while back...
my script would run perfectly when called from the command line but not if called by cron Sad
The script was kept in my home/bin directory in "/home", apparently "/home" was not mounted as executable.

My solution was to create a directory "/ubin" in "/", then a directory "/ubin/each_user" change ownership and permissions of the directory, then move my bin to "/ubin/each_user/bin" and replace it with a symlink.

Once my script was in the same partition as "/bin/bash" everything worked Smile



_________________
SuSE 8.0, 8.2, 9.0, 9.1, 9.2, 9.3, 10.0, 10.1, 10.2, 10.3, 11.0, 11.1
Live CDs Mepis 8.0, Puppy 4.3.1, netbook- Zenwalk 6.2
Back to top
View user's profile Send private message Visit poster's website
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sun Oct 12, 2024 11:41 am    Post subject: Reply with quote

Well, I really dunno what I did, but the cron job now runs. Very Happy Still seems to have issues writing to the file, but if I create the file to be copied to crontab with the text already in place it works. I think it is a directory permission issue, but since it works now I'll take it. Smile Just means I have to manually update if I want to change anything, but that's OK.

Thanks
Mick



_________________
Kubuntu
Back to top
View user's profile Send private message
mickwish
Jr. Member


Joined: 30 Aug 2024
Posts: 86
Location: Brisbane, Australia

PostPosted: Sun Oct 19, 2024 4:58 am    Post subject: Reply with quote

Well, that was embarrassing! Just worked out why the script wouldn't run - forgot to parse the script file for line breaks! Embarassed oRemoved those st00oid winders carriage returns and it runs fine.

Gotta remember to use the Unix converter in Notepad Plus in future. Embarassed

Thanks for your help in this guys, got it all working now.

Cheers
Mick the embarrassed Shocked



_________________
Kubuntu
Back to top
View user's profile Send private message
d_riordan
Member


Joined: 08 Jan 2024
Posts: 245
Location: Leominster, Massachusetts, U.S.A.

PostPosted: Sun Oct 19, 2024 10:16 pm    Post subject: Reply with quote

mickwish wrote:
Well, that was embarrassing! Just worked out why the script wouldn't run - forgot to parse the script file for line breaks! Embarassed oRemoved those st00oid winders carriage returns and it runs fine.0


Actually, that's really interesting. I had not idea that a carriage return could have a detrimental effect on a script.

Was anyone else aware that this could be a problem?



_________________
*buntu 8.04
Back to top
View user's profile Send private message Visit poster's website
Lord.DragonFly.of.Dawn
Advanced Member


Joined: 18 Jul 2024
Posts: 606
Location: South Portland, Maine, USA, Earth, Sol System

PostPosted: Mon Oct 20, 2024 12:28 am    Post subject: Reply with quote

I ran into that problem a few times, but only in specialized uses that required accurate counting of lines processed.

I don't run into it often and it has never caused an error like the one described but it does exist and some scripts may run into it depending on how they process input data.

-P



_________________
ArchLinux x86_64 - Custom Built Desktop
ArchLinux x86_64 - Compaq CQ50 Laptop
ArchLinux i686 - Acer Aspire One Netbook
ArchLinux i686 - Dell Presario ze2000 (w/ shattered LCD)

PuppyLinux, CloneZilla, PartedMagic, DBAN - rescue thumbdrives
Windows 7 (x86_64 desktop alternate boot)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    USA Linux Users Group Forum Index » Servers and Server Administration All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All content © 2024-2009 - Usa Linux Users Group
This forum is powered by phpBB. © 2024-2009 phpBB Group
Theme created by phpBBStyles.com and modified by Crouse