I have a situation where I'm testing a new filesystem that has an issue with some metadata. All of the files are intact, however I ultimately have to effectively move every single file off to another volume and then immediately back in place.
Obviously mv
won't do the trick since it's not able to preserve all attributes (particularly all timestamps). I was thinking something more along the lines of a find command whilst exec'ing cp -p /original/path/to/file /tmp/location/file
, rm /original/path/to/file
, cp -p /tmp/location/file /original/path/to/file
, rm /tmp/location/file
. Perhaps all of these commands in a script that is passed to the find exec?
I'm not sure of the most efficient approach here, but would like some quick input in order to make sure I cover all of my bases and have a precise command that will not leave me mourning some kind of data attribute loss when it's all said and done. I have many hundreds of gigabytes to shift back and forth so I need to be both as careful and as efficient as possible.
Here's the solution I've come up with so far and would love some input:
Shell script safe_move.sh
:
#!/usr/bin/env bash
SRC_FILE_AND_PATH="$1"
SRC_BASENAME=`basename "$1"`
DESTINATION_PATH="/mnt/tmp"
cp -a ${SRC_FILE_AND_PATH} ${DESTINATION_PATH}/${SRC_BASENAME}
rm -f ${SRC_FILE_AND_PATH}
cp -a ${DESTINATION_PATH}/${SRC_BASENAME} ${SRC_FILE_AND_PATH}
rm -f ${DESTINATION_PATH}/${SRC_BASENAME}
And this will be called with:
find /path/to/move -type f -exec safe_move.sh {} \;
Any thoughts or corrections?
- I did find a problem where this will ALTER folder dates due to modification of the folder's children... hrm. Not sure how to overcome this one yet.
Consider using
tar
with-p
(--preserve
). That way you also have a nice tarball to keep around... you know... just in case. There is no metadata that I am aware of that would be left behind. I also disclaim any responsibility if I am found to be wrong. =)EDIT: symlink dates won't be preserved! See?! Never trust a cat with root privileges.
Other options include
cplv
but you don't have a volume group that is at least the size of the source.cpdup
too. If it's all on the same volume group,rsync
might be an option.I noticed that you've marked this with the FreeBSD tag. If FreeBSD is your OS, then
The other commands you will need are
You want to replace these device nodes with ones that are appropriate for your system. Also, you want to stick to dumping whole partitions and shy away from dumping parts of a partition.
I found that rsync ultimately does the trick very well, except you have to remove the leftover folders that the process leaves behind. Unfortunate, but since the folders consume very little space, it's negligible and the rm is acceptable: