backup icon indicating copy to clipboard operation
backup copied to clipboard

deleteoldbackups.sh uses /root/backups

Open nigelhorne opened this issue 9 years ago • 11 comments

Why does deleteoldbackups.sh give this error:

/backups/bin/deleteoldbackups.sh: line 59: cd: /root/backups/: No such file or directory

/root/backups appears nowhere in my configuration file:

root@nigelhorne:/backups/bin# fgrep /root * root@nigelhorne:/backups/bin# ls -l total 20 -r-------- 1 root root 2184 Jul 24 14:14 backup.cfg -rwxrwxr-x 1 root root 4318 Jul 24 14:16 backup.sh -rwxrwxr-x 1 root root 5438 Jul 24 13:39 deleteoldbackups.sh root@nigelhorne:/backups/bin#

nigelhorne avatar Jul 24 '15 13:07 nigelhorne

Bizarre... /root/backups isn't 'hard-coded' anywhere within the deleteoldbackups.sh script. It should be loading the config from your backup.cfg. Are you absolutely certain you do not have /root/backups set in your config for either REMOTEDIR or LOCALDIR.

The phrase '/root/backups' only exists within the config...it is not hard coded anywhere.

ReidWeb avatar Jul 24 '15 14:07 ReidWeb

Not that I can see, which is why I included the output of the grep command in my report. Unless I should be looking somewhere else that I missed as well.

nigelhorne avatar Jul 24 '15 14:07 nigelhorne

Hmm... Could you please paste LOCALDIR and REMOTEDIR from backup.cfg?

xCP23x avatar Jul 24 '15 14:07 xCP23x

A possibility is that when you ran the backup script previously, it's populated your environment variables with the contents of the script, and for whatever reason re-running the script isn't overwriting them. The easiest way to check would probably be to just try echo $LOCALDIR and echo $REMOTEDIR.

EDIT:

Apologies, I was not aware that Bash actually had a concept of scoping for environment variables, so the script won't interfere with your bash environment out of the script.

Pricetx avatar Jul 24 '15 15:07 Pricetx

... Checking for LOCAL backups to delete... /backups/bin/deleteoldbackups.sh: line 59: cd: /root/backups/: No such file or directory

Checking for REMOTE backups to delete... Deleted 0 backups, freeing 0.00 B 0 backups remain, taking up 0.00 B

All done. Backup and transfer completed in 6 seconds

root@compaq:/backups/bin# echo $LOCALDIR

root@compaq:/backups/bin# echo $REMOTEDIR

root@compaq:/backups/bin# fgrep LOCALDIR *cfg LOCALDIR="/backups/compaq/" root@compaq:/backups/bin# fgrep REMOTEDIR *cfg REMOTEDIR="/backups/compaq/" root@compaq:/backups/bin#

nigelhorne avatar Jul 24 '15 16:07 nigelhorne

Hmm, that's very strange. Could you please try manually running "deleteoldbackups.sh" and "deleteoldbackups.sh --remote", and see if either or both of them give the "No such file or directory" error.

The first command should use $LOCALDIR and the second should use $REMOTEDIR. I'm really unsure as to where it's grabbing /root/backups from though, as it's not in the environment, or the variables, or even hardcoded.

Pricetx avatar Jul 24 '15 16:07 Pricetx

root@nigelhorne:/backups/bin# ./deleteoldbackups.sh ./deleteoldbackups.sh: line 59: cd: /root/backups/: No such file or directory root@nigelhorne:/backups/bin# ./deleteoldbackups.sh --remote Deleted 0 backups, freeing 0.00 B 1 backups remain, taking up 4.22 MiB root@nigelhorne:/backups/bin#

I don't understand it either :-(

nigelhorne avatar Jul 24 '15 16:07 nigelhorne

Also I just did this:

root@nigelhorne:/backups/bin# env | grep /root MAIL=/var/mail/root HOME=/root

So it's not coming from the environment I already have.

nigelhorne avatar Jul 24 '15 16:07 nigelhorne

Ah, at least based on your output from deleteoldbackup.sh it appears that it's only $LOCALDIR that has the issue. I suppose as a next step you could possibly try re-downloading the files, and seeing if the issue persists.

Pricetx avatar Jul 24 '15 16:07 Pricetx

I tried, but no change.

nigelhorne avatar Jul 24 '15 18:07 nigelhorne

Perhaps it happens because for some reason BACKUPDIR isn't set.

How about a wrapper such as this (untested)

if [ "x$BACKUPDIR" == x]; then echo "BACKUPDIR not set" 1>&2 exit 1; fi

cd "${BACKUPDIR}" || exit 1

Or better still check that LOCALDIR and REMOTEDIR are set when setting BACKUPDIR.

nigelhorne avatar Aug 12 '15 13:08 nigelhorne