0
I have a shell script that deploy an application to a staging server. However, one of the application's directory needs to be backed up and restored after the deployment (so it is not overwritten). I manage to backup the directory, but the restore part does not behave as expected. Basically, here are the two lines in the shell script :
...
# backup user avatars
mv vitex/app/modules/users/pub/img/users/ ~/tmp/img-users.BAK/ &> /dev/null
...
# restore user avatars
mv ~/tmp/img-users.BAK/ vitex/app/modules/users/pub/img/users/ &> /dev/null
The problem is that the first command creates the correct folder under ~/tmp/
, but the second command creates vitex/app/modules/users/pub/img/users/img-users.BAK/
, which is not good.
The expected behaviour would be that img-users.BAK
would move all files back, overwritting any files in the destination folder, leaving any other files untouched.
How can this be done?
Thanks!
Note: recursivity is not necessary as there are no directory under that path.
** Edit **
Step 1 : backup directory
Before
./vitex/app/modules/users/pub/img/
./users/
./1.png
./14.png
./README
...
./tmp/
<empty>
After
./vitex/app/modules/users/pub/img/
<empty>
./tmp/
./img-users.BAK/
./1.png
./14.png
./README
...
Everything is as expected.
Step 2 : Restore directory
Before
./vitex/app/modules/users/pub/img/
./users/
./1.png
./3.png
./README
...
./tmp/
./img-users.BAK/
./1.png
./14.png
./README
...
After (actual)
./vitex/app/modules/users/pub/img/
./users/
./img-users.BAK/
./1.png
./14.png
./README
...
./3.png
./1.png
./README
...
./tmp/
<empty>
After (expected)
./vitex/app/modules/users/pub/img/
./users/
./1.png <-- overwritten
./14.png
./3.png
./README <-- overwritten
...
./tmp/
<empty>
Had to add
rm -Rf ~/tmp/img-users.BAK
after moving the files, though. But this works. Chose this because of the-f
flag, too. – Yanick Rochon – 2014-09-17T20:10:55.370Probably don't want the
-Rf
, justrmdir
, under the theory that the directory should be empty (ignoring dot files) after themv
completed. Moreover, if themv
failed, you probably really don't want to recursively remove the temp dir and it's contents, which are still useful, presumably. – crimson-egret – 2014-09-17T23:48:43.797You would be right, however if the process fail, I just revert the VM to the previous snapshot (part of the script), as the
mv
andrm
commands are being executed through SSH. I didn't mention this as it has nothing to do with the question here. – Yanick Rochon – 2014-09-18T00:35:08.280