Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleteoldbackups.sh uses /root/backups #17

Open
nigelhorne opened this issue Jul 24, 2015 · 11 comments
Open

deleteoldbackups.sh uses /root/backups #17

nigelhorne opened this issue Jul 24, 2015 · 11 comments

Comments

@nigelhorne
Copy link

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#

@ReidWeb
Copy link
Contributor

ReidWeb commented Jul 24, 2015

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.

@nigelhorne
Copy link
Author

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.

@xCP23x
Copy link
Collaborator

xCP23x commented Jul 24, 2015

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

@Pricetx
Copy link
Owner

Pricetx commented Jul 24, 2015

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.

@nigelhorne
Copy link
Author

...
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#

@Pricetx
Copy link
Owner

Pricetx commented Jul 24, 2015

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.

@nigelhorne
Copy link
Author

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
Copy link
Author

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.

@Pricetx
Copy link
Owner

Pricetx commented Jul 24, 2015

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.

@nigelhorne
Copy link
Author

I tried, but no change.

@nigelhorne
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants