2
We're running a backup script which first copies a file to a destination and then runs tar
over it.
DIR2BCK='/foo/bar'
TMPDIR=$(mktemp -d)
rsync -a ${DIR2BCK} ${TMPDIR}/ > /dev/null 2>&1
tar czf /tmp/foo.backup.tar ${TMPDIR}
After running this last command, sometimes the following warning is shown:
/tmp/tmp.blqspkA136: file changed as we read it
We copy the destination to a temporary directory precisely to avoid file changes at compression time. This behavior is also reproducible when using the cp
command instead of rsync
. All my life I thought these commands were synchronous, but this warning seems to show the opposite.
If I put a sleep
command between the rsync
/cp
and the tar
lines, the warning doesn't show up, but I consider this a not quite clean solution.
Some facts:
- I tried adding a
sync
command between thersync
andtar
commands with same result. As suggested by @jcbermu I also tried changing the script so the two lines are:
rsync -a ${DIR2BCK} ${TMPDIR}/ > /dev/null 2>&1 & wait
I run the script several times and some of them shown the same behavior, claiming the file changed when copying.
The filesystem used is EXT4 both for
${TMPDIR}
and${DIR2BCK}
.${DIR2BCK}
is on a remote filesystem, actually this is a samba mountpoint of a remote machine.${TMPDIR}
is on the local filesystem. However, changing${DIR2BCK}
to the local filesystem makes no difference.- All filesystems are hardware RAID-5 based.
Are these commands actually synchronous? If not, is there a way to make them so, or an alternative command?
Yes, these commands are done when they exit. You are not quoting file/directory names. Please fix that ASAP. – Daniel B – 2017-09-29T11:43:43.057
@DanielB My mistake. Although the logics is the same, this is not the actual code. The real one includes the quotes. – nKn – 2017-09-29T11:49:27.980
Well then perhaps there is a subtle mistake in the real code. Or is the code above actually enough to reproduce the issue? – Daniel B – 2017-09-29T11:54:17.977
Yes, it should be enough, as paths are correct. The major issue is that when
tar
starts,rsync
/cp
don't seem to have ended copying yet, and the warning is shown. I assumed these commands are synchronous, that's why I'm surprised. – nKn – 2017-09-29T11:58:38.113Don’t assume, try. Otherwise, a qualified answer cannot be provided. //
sync
is not helping here. You’re not accessing raw data on devices. // Please also provide information about which filesystems both$TMPDIR
and$DIR2BCK
reside on. – Daniel B – 2017-09-29T20:06:57.137Are both $TMPDIR and $DIR2BCK on the same filesystem? or are they separate drives or partitions? Are you using regular hard drives/ssd's or some sort of RAID? – arielnmz – 2017-10-02T17:09:03.093
@arielnmz they are on separate filesystems,
${TMPDIR}
is actually a samba share on a different machine, but this also happened when both where on the same filesystem. All filesystems are on RAID5. – nKn – 2017-10-02T17:24:07.007