DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#326 2013-01-09 01:33:53

fweijer71
New member
Registered: 2013-01-09
Posts: 3

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

I have a Cron issue with my DNS323.

I have a NAS1 (a DNS323) that makes a backup to another NAS2 using a scheduled rscync script which starts around 04:05.
NAS1 has a user account "backup" which is able to ssh to NAS2 using no password. (rsync uses ssh under water so this is convenient).
The script is started via a cron job.

However, when the script is run via cron, I get this error message:

Code:

rsync: Failed to exec ssh: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(84) [sender=3.0.5]
rsync: writefd_unbuffered failed to write 4 bytes [sender]: Broken pipe (32)
rsync error: error in IPC code (code 14) at io.c(1509) [sender=3.0.5]

When I start the script as root, it all works fine.
Who understands what needs to be solved? Thanks very much!

The cron job entry is this:

Code:

root@DLINK:~# crontab -l
5 4 * * * /ffp/bin/snapshotMYBOOKWORLD.sh

This is the script:

Code:

root@DLINK:~# more /ffp/bin/snapshotMYBOOKWORLD.sh
#!/bin/sh

# Dit script is voor de MYBOOKWORLD
# User backup van de Dlink kan zonder password ssh naar user fweijers op de Mybookworld.

srcpath='/mnt/HD_a2/DOCUMENTEN /mnt/HD_a2/VIDEO/EIGEN* /mnt/HD_a2/FOTOS'

datum=`date "+%Y%m%d_%H%M%S"` 
echo $datum >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1

/ffp/bin/su -c "/ffp/bin/rsync -av $srcpath fweijers@192.168.178.100:/shares/internal/BACKUPNAS >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1" backup

datum=`date "+%Y%m%d_%H%M%S"` 
echo $datum >> /ffp/log/snapshotMYBOOKWORLD.log 2>&1
root@DLINK:~#

As you can see, I used a "su -c <command> <username>"  construction.
My thought was that there lies the problem …I was thinking of PATH settings for user backup, but those PATH settings seem ok:

Code:

root@DLINK:~# echo $PATH
/ffp/sbin:/usr/sbin:/sbin:/ffp/bin:/usr/bin:/bin
root@DLINK:~# su - backup
backup@DLINK:~$ echo $PATH
/ffp/bin:/usr/bin:/bin
backup@DLINK:~$ 

root@DLINK:~# ls -l /ffp/bin/ssh
-rwxr-xr-x    1 root     root       256336 May 19  2009 /ffp/bin/ssh
root@DLINK:~# ls -l /ffp/bin/rsync
-rwxr-xr-x    1 root     root       373820 Mar  3  2009 /ffp/bin/rsync

How do I get the PATH settings correct for user "backup" when this script is started via Cron?
Cheers!

Last edited by fweijer71 (2013-01-09 01:35:05)

Offline

 

#327 2013-01-09 10:36:24

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

I am thinking the same thing, it's probably the path. Since cron is starting the shell in a non-interactive mode it initialization is a bit different and that may include setting path differently, although it's running with the same UID (user ID).
the su -c is redundant, I think.

add to the beginning of the script:

Code:

echo $PATH > /tmp/echo_path.txt

or

Code:

env > /tmp/echo_path.txt

and run it from crontab to see what the running environment is like.
You can add a line to the script to set PATH.


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

#328 2013-01-09 15:38:35

Loose Gravel
Member
Registered: 2008-10-14
Posts: 50

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

scaramanga is right. The cron environment is missing the path to the ffp binaries. So /ffp/bin/ssh is not found because /ffp/bin is not part of your path. This happens on some boxes (i dont know the reason. Firmware?)

The solution is to add
   export PATH=/ffp/sbin:/ffp/bin:$PATH
as the second line in your script setting up the ffp environment.



Loose

Offline

 

#329 2013-01-09 15:43:39

Loose Gravel
Member
Registered: 2008-10-14
Posts: 50

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

And if this doesn't work try to add

Code:

export RSYNC_CONNECT_PROG='/ffp/bin/ssh'

or add the parameter

Code:

--rsh=/ffp/bin/ssh

to your rsync command.

Offline

 

#330 2013-01-09 22:10:06

fweijer71
New member
Registered: 2013-01-09
Posts: 3

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

Thanks a lot for your suggestions!
I will try the

Code:

 export PATH=/ffp/sbin:/ffp/bin:$PATH

as the second line the script first. I will let you guys know soon if it solves the issue.

Some background about my configuration
I had the backup script from the start of this thread which backups Disk1 tot Disk2 in the DNS323 running for a long time.
Then I got another NAS in my home, which I started using as an "off-site backup". smile
I put it in my barn (you know, a thief will not rob both your house and you barn! smile I hope big_smile) and had a copy backup script running almost the same rsync command as the Disk-copy, but this time from NAS1 to NAS2.

In order to do so, I had to make a ssh key-sharing solution because rsync uses ssh under water. The password-less ssh solution can be found here : http://www.linuxproblem.org/art_9.html

This setup worked fine, as long as the DNS323 doesn't reboot. When this happens, the file system is rebuild, wiping all the shared keys, making the password-less ssh stop, and thus failing the rsync command ...

So I created a user called 'backup', moved his homedir to Disk1

Code:

 usermod -d /path/to/new/homedir/ username

and this way preventing the ssh keys from being wiped after a reboot.

This almost works ... wink first hopefully the suggested PATH-fix for crontab works.
After that, it appears that after a reboot the moved homedir of user backup cannot be found.... so I think I need to insert the usermod command in some script that is always run after a reboot of the DNS323.

Any suggestions for such a script?

Maybe someone can use my solution too ... It is very nice to have your precious date backed-up to another site on a daily basis!

Offline

 

#331 2013-01-10 08:51:14

fweijer71
New member
Registered: 2013-01-09
Posts: 3

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

Thanks Scaramanga and Loose Gravel!
The suggestion export PATH=/ffp/sbin:/ffp/bin:$PATH in the script works! big_smile

Any suggestion to have the home directory of a user moved, after a reboot?
This is the required command (somehow this is lost after a reboot ??

Code:

 usermod -d /mnt/HD_a2/home/backup backup

Offline

 

#332 2013-01-10 13:47:53

scaramanga
Member
Registered: 2010-08-04
Posts: 251

Re: Tutorial: Backup Everything from Vol A to Vol B once a night

fweijer71 wrote:

Thanks Scaramanga and Loose Gravel!
The suggestion export PATH=/ffp/sbin:/ffp/bin:$PATH in the script works! big_smile

Any suggestion to have the home directory of a user moved, after a reboot?
This is the required command (somehow this is lost after a reboot ??

Code:

 usermod -d /mnt/HD_a2/home/backup backup

There's a script that updates/stores it to flash: store-passwd.sh


DNS-323 HW Rev. C1 FW 1.10 fun-plug 0.5
2 x WD10EARS-00Y5B1 in Standard mode (LCC set to 5 min; Aligned to 4K)
Transmission with Transmission Remote GUI

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB