I am trying to automate a remote backup on our centOS server, I run the current command :
nice -n 10 mv -vfb /media/localbackup/* /media/remotebackup/
however when this is ran I get the following error and no files are moved
mv: inter-device move failed: `/media/localbackup/04-21-13' to `/media/remotebackup/04-21-13'; unable to remove target: Is a directory
I have been told it is better to use cp however this won't delete the files afterwards and I need to remove the files upon successful backup.
Best Answer
I also suggest you using
rsync
instead ofmv
, but adding to @Hartmut's answer:And 2 additions here:
-m
(--prune-empty-dirs
) parameter torsync
, which on my version 3.0.7 protocol version 30 says: prune empty directory chains from the file-list but doesn't do that for some reason. Doesn't error either (not the only one to notice it).find
command which will delete the empty directories.now, the reason against
cp
&&rm
is thatcp
might fail half-way through. The next time you want to backup you will be in a weird situation (partially copied files to name the worst case). Also, the next backup will not know what to do with the previously backed up files which were not deleted. On the other handrsync
covers these aspects just fine.Also, using a script (as first answer suggests) to do what rsync already does, but worse, is a no-go (sorry Hauke Laging :-) ). No need to reinvent the wheel here.