I am needing to write a script that will move files to a destination location (off volume), remove the original file and directories and then move them back to their original location while preserving all attributes.
The concept is rather simple algorithmically, however the real hangup I’m having is recursing the tree properly when I’m using rsync.
So far it appears that rsync -axvvES --remove-source-files source_directory /destination/ is the most efficient solution for copying files over, however, as noted, I cannot simply allow rsync to recurse the tree itself due to size constraints. Ultimately I think find can be used to drill down and then allow rsync to run, however how can I descend to the lowest point first with find in order to accomplish this goal?
UPDATE:
Ultimately this seemed to do the trick satisfactorily:
echo -e "Moving over... "
rsync -axvES --remove-source-files ${SRC_FILE_AND_PATH} ${DESTINATION_PATH}/
echo -e "Bringing back... "
rsync -axvES --remove-source-files ${DESTINATION_PATH}/${SRC_BASENAME} ./
It does leave folders in the working directory, but since it does overwrite attributes correctly on the initial folder on the move back, it’s satisfactory and in the end I can just rm the empty remaining directories.
The
findcommand has a-depthswitch which makes it behave like you ask for.