Here is some code of mine:
gzip -c $path > /var/www/wiki/backup/$now/$file.gz
I'm gzipping the contents of $path (the path to a directory), and then sending the compressed file to /var/www/wiki/backup/$now/$file.gz. $now contains a directory name, $file is the name I want to write the compressed file to.
However, on running the program, I get this error:
backup.sh: line 20: /var/www/wiki/backup/Sunday/extensions.gz: No such file or directory
^$now ^$file
(line 20 is the line given above)
Why is the program breaking? I know Sunday/extensions.gz doesn't exist (although Sunday does), that's why I'm asking you to write to it!
Full program code:
#!/bin/bash
now=$(date +"%A")
mkdir -p /var/www/wiki/backups/$now
databases=(bmshared brickimedia_meta brickimedia_en brickimedia_customs)
locations=("/var/www/wiki/skins" "/var/www/wiki/images" "/var/www/wiki/")
for db in ${databases[*]}
do
#command with passwords and shoodle
:
done
for path in ${locations[*]}
do
#echo "" > var/www/wiki/backup/$now/$file.gz
file=`echo $path | cut -d/ -f5`
echo $path
gzip -c $path > /var/www/wiki/backup/$now/$file.gz
done
The directory created is backups, the gzip is to backup.
mkdir -p /var/www/wiki/backups/$now
gzip -c $path > /var/www/wiki/backup/$now/$file.gz
One of your locations is "/var/www/wiki/". Then you have
file=`echo $path | cut -d/ -f5`
gzip -c $path > /var/www/wiki/backup/$now/$file.gz
Since $file contains the empty string, you're attempting to write to /var/www/wiki/backup/Sunday/.gz. That's a problem but it's not the error you're reporting.
When I try to gzip a directory, I get this error
$ gzip -c ./subdir/ > subdir.gz
gzip: ./subdir/ is a directory -- ignored
That's a problem but it's not the error you're reporting.
@suspectus solved your reported problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With