I made a save script, to save some directories in my /home
. To do that I loop through the directories in /home, and launch a save for each of them.
These directories contain jar files, and some .txt
. Properties and other directories. The first time I launch the script it worked great. I modified it, but yesterday when I try some feature it goes wrong and I can not find why.
I have this error when I use the tar -cjf
command to create .tar.zip archive.
tar: home/myFolder : impossible stat: no file or folder of this type
backupdate=$(date +%Y-%m-%d) dirbackup=/save/$backupdate mkdir $dirbackup list_dossier=`ls ../home` for server in $list_dossier do tar -cjf $dirbackup/$server.tar.zip home/$server done
EDIT
I’m trying to keep this shape of save : a folder with name the date, and in it, X archves contain my X folders of my /home
#!/bin/bash backupdate=$(date +%Y-%m-%d) dirbackup=/save/$backupdate mkdir $dirbackup for server in /home/* do echo $server"test" tar -cjf $dirbackup$server.tar.zip $server done exit
Answer
This line will cause problems:
tar -cjf $dirbackup$server.tar.zip $server
That’s because $server
would be something like /home/myserver
and so this command would expand to
tar -cjf /save/2019-04-13/home/myserver.tar.zip /home/myserver
Note the extra /home
in the path to the tarfile.
Instead we can change directory before hand..
#!/bin/bash backupdate=$(date +%Y-%m-%d) dirbackup=/save/$backupdate mkdir $dirbackup || exit cd /home || exit for server in * do echo $server"test" tar -cjf $dirbackup$server.tar.zip $server done