1

So we have a bunch of src files that are old and out-dated and need to be moved to our new NAS storage. (I don't know why we are keeping them).

  • Is it possible to copy all the files and folders with their directories over to the new drive?
  • The directories are not already made on the new storage drive.
  • Can a command do this or do I have to make a script?

Has anybody done something similar to this?

1 Answer 1

2

Yes you can do this if you have a system where both the src files are accessible and the NAS. There are several ways to do this with a single command, but the tool rsync is probably the best one to go with:

$ sudo rsync -avz src /mnt/NAS/ 

The switches (from the rsync man page):

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) -v, --verbose increase verbosity -z, --compress compress file data during the transfer 

So the -a switch is actually a macro for a whole bunt of switches:

-r, --recursive recurse into directories -l, --links copy symlinks as symlinks -p, --perms preserve permissions -t, --times preserve modification times -g, --group preserve group -o, --owner preserve owner (super-user only) -D same as --devices --specials 

Running as root

You'll want to run this as root to preserve the permissions and ownerships of the files + directories. Also this particular root user will need access to the NAS. This is sometimes not setup by default so you may need the help of an admin if you're not the one.

Before you get started

Typically you'll want to do some upfront analysis on the directories in question to see if there are any symbolic links or fifo type files. These will require additional switches to rsync so that it recreates them correctly in the target directory.

No direct mounting access to NAS

All is not lost if you can't directly mount the NAS on the same box where you have access to the src files. You can also rsync over ssh.

$ sudo rsync -avz src root@remoteserver:/mnt/NAS/. 

There are more advanced options if neither of these suite your needs.

3
  • Hi slm, looks promising but what exactly do the options -avz do? src is the location of where I want to start copying folders correct? Sorry for the noob like questions but I'm not familiar with this cmd/tool at all. Commented Aug 8, 2013 at 16:40
  • @mkrouse - NP. src is where you'd copy from. I'll add some detalis to the answer about the switches. Commented Aug 8, 2013 at 16:50
  • @mkrouse - I highly suggest looking at the man page. It covers much of how rsync works. man rsync. Commented Aug 8, 2013 at 16:57

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.