When you move a file within the same filesystem, mv
detaches the file from its old location and attaches it to its new location; metadata such as permissions remains the same. When you move a file to a different filesystem, mv
copies the file, attempts to replicate as much metadata as possible, and removes the original.
Since you're moving to a different filesystem and you don't want to replicate much metadata, you might as well copy the file then remove the original.
cp "$backupfile" "$destination" && rm "$backupfile"
This preserves the file's permissions to some extent (e.g. world-readability, executability). The file's modification time isn't preserved. With GNU cp
, you can use the --preserve=…
option to contol what metadata is replicated more finely, e.g. --preserve=mode,timestamps
.
You can also use rsync
and tell it what you want to preserve. The option -a
means “preserve most metadata”, which includes the owner if running as root only.
rsync -a --no-owner --no-group --remove-source-files "$backupfile" "$destination"
cifs
).sshfs
mount, even if it's mounted with-o idmap=user
, because the gid does not get mapped (even with-o gidfile
).