The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - General (http://hintsforums.macworld.com/forumdisplay.php?f=16)
-   -   Need help with rSync (http://hintsforums.macworld.com/showthread.php?t=81339)

wiitho 11-15-2007 02:10 AM

Need help with rSync
 
Hello!

I need help with making an rSync script.
I want the script to backup my homefolder, \Macintosh HD\Users\Me
to my NAS disk \\192.168.65.100\share.
Im going for rSync since it only transmit the changes in a file on bit level.

Also, as this disk is on the network, I will probably need something to make the login happen. The username and passoword is simply admin / admin.

Im planning to insert the script into the daily script. That way it wil run automatically every nigth, and Ill also have an easy way of running it manually.

If someone could show me a script that would do this I would be grateful.
Thanks!

son_t 11-15-2007 06:32 AM

'man rsync' would give you the options you want.

The command would be:
Quote:

rsync -[options] /source/directory /target/directory
An example would be:
Quote:

sudo rsync -av /Users/son_t/Downloads /Users/test/Downloads
Not sure how your NAS is shared but rsync works with SSH so it needs to be running that protocol to work... Or you can mount the samba share provided by your NAS with an Applescript and then use the above...

This is the Applescript (saved say in /Users/me/mount as an application):
Code:

tell application "Finder"
        mount volume "smb://admin:admin@192.168.65.100/share"
end tell

This would be the shell script:
Code:

#!/bin/sh
/Users/me/mount
rync -av /Users/me /Volumes/share


wiitho 11-16-2007 02:08 AM

Thanks for your reply!

What would be the difference between \Users\Me\ and \Users\Me ?

GimmeSlack12 11-19-2007 01:20 PM

The difference between \Users\Me\ and \Me
is that the directory \Me\ will be copied, so that you will now have a NAS\Share\Me\(files) on your NAS. Where if you use \Me you will get NAS\Share\(files).

Hope that makes sense.

tlarkin 11-19-2007 01:22 PM

Also, if you toss the -u switch in there, it will only update the rsync when files are modified or data is added, so it will basically synchronize your data from one share to the next. There are some caveats though, like for example there are known issues with it preserving time and date stamps on data.

Also, when writing a script it is best practice to actually type in the full paths of commands

Code:

#!/bin/bash

#this script will run rsync on home directory to a set NAS share

/sbin/mount mountpoint

/usr/bin/rsync -r -o -u /path/to/home /path/to/nas


cwtnospam 11-19-2007 01:59 PM

Don't you need the -E switch, so rsync includes resource forks?

tlarkin 11-19-2007 02:00 PM

Quote:

Originally Posted by cwtnospam (Post 426668)
Don't you need the -E switch, so rsync includes resource forks?

-E just copies extended attributes, you can add it if you wish

cwtnospam 11-19-2007 02:05 PM

I mentioned it because I had a problem transferring some files that had resource forks. I didn't get to confirm that -E would work (it does locally) over a network, because I was transferring to a Panther system, and apparently -E wasn't included in Panther's rsync!

wiitho 11-19-2007 02:23 PM

Thanks for your help!
Ill see if I get the time to test a scripts tomorrow :)

The \Me\ or \Me clarification made perfect sense :) Thanks!

wiitho 11-20-2007 05:02 AM

So the full code would be:

/sbin/mount afp://admin:admin@192.168.0.80/nas

/usr/bin/ rsync -r -o -u ~/ /Volumes/nas/


Where should this shellscript be stored?
Will I be able to start it manually and via the daily routine in a simple way?
Thanks again :)

agentx 11-20-2007 08:10 AM

rsync backup to SFTP server...
 
Not sure if anyone can help.....

I have an important database file that i need to backup offsite to an FTP server (or ideally by SCP/SSH/SFTP)

Can somebody help with a shell script that i can use to do this.
I just need to replace the file remotely with file from server on a daily basis.

I will use launchd to get the script to run....

cwtnospam 11-20-2007 08:22 AM

You could use:
scp /path/to/filename.ext username@address:/path/to/filename.ext

tlarkin 11-20-2007 09:01 AM

Savage-

just mount the volume before you run the script, you can mount FTP via the finder. I think it should work, test it out.

agentx 11-20-2007 09:48 AM

hi there tlarkin......

Indeed this should be easy to sort out but have once again been running into trouble.

The key thing is this server is not maintained on a daily basis, I look at it once a week....so really need something pretty bullet proof to implement.

There are onsite daily backups which are handled by retrospect to hard disks, a once a week rsync back up to an offsite drive(manually done by an advanced user) and now with the implementation of a new FM CRM/Project management system it is imperative to get the databases offsite daily.

I need two FM databases backed up to a remote FTP space on a daily basis.
Ideally without the use of flakey finder FTP mount which tends to fail.

any ideas of how i can do this.....???

tlarkin 11-20-2007 10:20 AM

does it have to be FTP? Can you rsync it to a NFS share or something else?

agentx 11-20-2007 11:01 AM

in short no it is a remote webserver....
I can ssh,ftp,sftp to server

tlarkin 11-20-2007 11:10 AM

you could connect the mount point over ssh, then use rsync.

cwtnospam 11-20-2007 11:14 AM

I notice that Cyberduck is Applescript aware and it has a sync capability...

agentx 11-20-2007 05:14 PM

I will give it a go.
thx

son_t 11-21-2007 04:33 AM

Quote:

Originally Posted by tlarkin (Post 426962)
you could connect the mount point over ssh, then use rsync.

I was going to ask how to do this, but google-is-my-friend: http://lifehacker.com/software/ssh/g...ssh-246129.php

wiitho 11-28-2007 04:48 AM

Hello again!

Thanks for all your help. Scripting is not something Im very good at, so Im sorry about asking the same questions over and over... Hope someone can clarify a few things for me:
1. Where do I create the shellscript (textedit or terminal)?
2. Where should I save it
3. If its called "backup.sh" or "backup.command", how will I start it from the terminal? I need to be able to do this both from the prompt and within the daily routine
4. Should it be saved as *.sh or *.command?
5. Below I have tried to make the script as I have understood your feedback. Does it seem correct?

#!/bin/bash

#this script will run rsync on home directory to a set NAS share

/sbin/mount afp://admin:admin@192.168.0.107/sonos/

/usr/bin/rsync -r -o -u -e /Volumes/Machintosh HD/Users/Me/ /Volumes/192.168.0.107/sonos/

Thanks again for your help :)

tlarkin 11-28-2007 08:58 AM

The script looks fine, you can create it in any text editor. I prefer text wrangler (google it, free download) but you can use Apple's text edit. Make sure that you you set text edit's preferences to always run as plain text. If you make a script as rich text it will not work.

Save the file as .sh.

Now, you can set up a cron job, or apple script to make it executable in the finder. The cron job will run the script at set time and date, and repeat as need be. The apple script would make it have the ability to run with in the finder not having to use the terminal.

wiitho 11-28-2007 09:04 AM

Thanks for your help!

So /path/to/backup.sh added to the /etc/daily would do the trick as a schedule.
And an AppleScript to make it excetutable manually?

tlarkin 11-28-2007 09:27 AM

check out these links they explain it in more detail

http://www.macosxhints.com/article.p...01020700163714

on this link scroll down to the crontab part

http://www.macdevcenter.com/pub/a/ma...minal_one.html

wiitho 11-28-2007 09:35 AM

Thanks again :)

wiitho 12-04-2007 09:25 AM

Hello again!

I cant make the script work in applescript...

tell application "Finder"
mount volume "afp://admin:admin@192.168.0.107/sonos/"
end tell

Works great and the disk connects. However, Im not able to make the script run:

do shell script /Users/Me/Desktop/Backup.sh

What would the syntax for this part be?
Can both functions be in the same script?

Thanks again for your help :)

cwtnospam 12-04-2007 10:02 AM

Try:
do shell script "/Users/Me/Desktop/Backup.sh"

wiitho 12-05-2007 02:55 AM

That seems to work. However, now I get an permissions denied message..
It does not help to put sudo in fornt of /usr/bin/rsync

cwtnospam 12-05-2007 08:45 AM

Do you have permission to execute the script: /Users/Me/Desktop/Backup.sh
Post what you see if you type this in a terminal window:
ls -la ~/desktop/Backup.sh

tlarkin 12-05-2007 09:28 AM

if he created it, he should have ownership, which by default gives you rwx permissions.

Are you logged in as administrator?

You may want to delete your bash profile under your user account, or better yet test it under a new user account and see if it still denies permission.

cwtnospam 12-05-2007 09:46 AM

Quote:

Originally Posted by tlarkin (Post 431537)
if he created it, he should have ownership, which by default gives you rwx permissions.

Not if it was created in TextEdit. He may only have rw–.

tlarkin 12-05-2007 10:35 AM

Really? In my experience everything I create script wise is owned by my user account, even in text edit. I typically save things in my home directory in a folder called 'scripts' then once it is fully tested I duplicate it and toss it on the network or the local client machines.

cwtnospam 12-05-2007 10:41 AM

Yes, it's owned by your user account, but TextEdit doesn't make its files executable. That would make the file rw– instead of rwx, so while it could be read or written to, it couldn't be executed as a script.
A simple:
chmod 7?? filepath

should take care if it, assuming that's the problem.

tlarkin 12-05-2007 10:50 AM

Oh, the difference is I always execute scripts manually, with the sh command, before I change ownership and permissions (to make it owned by root or whatever).

So, that is where I was getting confused, but a simple chmod +x /path/to/script will make it executable.

cwtnospam 12-05-2007 11:08 AM

The preferred method:
Quote:

Originally Posted by tlarkin (Post 431552)
chmod +x /path/to/script

:o I don't know why I always use the numbers instead of +/- and r,w,or x. I guess I just like converting from binary to decimal. :D Of course, in this case it's even more difficult my way because you need to determine the proper numbers for group and other.

tlarkin 12-05-2007 11:29 AM

well the difference is, +x makes it executable across the board, where the numbers 751 are for owner, group, everyone. So, you have more control. Each method has its use.


All times are GMT -5. The time now is 05:44 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.