1

I am currently working on a backup script to log into my production server and pull the latest SQL dumps to my staging server. I have no issue pulling the SQL dumps but I do have an issue with moving the last backup files to a temporary folder.

My backup script user: mysqlBackupUser

I am using this user's home directory as the location for this script and to store the backups. The folder structure is:

/home
   |- mysqlBackupUser
       |- .ssh
       |- backups
       |- bin

My script sits in bin and the backups are downloaded into the backups directory

The backups directory also has other folders to organize the server and type of the backups. I.E.:

/backups
   |-mysql
       |- production1
       |- production2
   |-misc
       |- production1
       |- production2

So far everything is fine and works as expected. The issue is when I am in (not limited to):

/home/mysqlBackupUser/backups/mysql/production1/

when I create the tmp directory named _lastBackUp and try to move my previous backups into it I get:

find: Failed to change directory: Permission denied

My code for this is:

local tmpBackUpDir="${LOCAL_LOCATION_DIR}/_lastBackUp/"

# Ensure the directory exist
mkdir -p "${tmpBackUpDir}"

# move any previous files to bak
find "${LOCAL_LOCATION_DIR}/" -type f -exec mv -t "${LOCAL_BAKUP_DIR}" {} \+;;

For clarity:

LOCAL_LOCATION_DIR = /home/mysqlBackupUser/backups/mysql/production1
tmpBackUpDir = /home/mysqlBackupUser/backups/mysql/production1/_lastBackUp/

To understand how the script is being used: Currently I am in as my user and I am

sudo su mysqlBackupUser

To be as the user. I am not sure if this is the issue and I cannot test by logging in as this user. The script will be run by cron and it will act as this user (keys are setup to ease the automation for this user) to do the process so I am not certain this is really the issue.

I have verified that the ownership and permission of all folders, even the _lastBackUp is owned by mysqlBackupUser. I even set _lastBackUp to 777 for testing and still got permissions denied...

My complete error is:

find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: Failed to change directory: Permission denied
find: failed to restore initial working directory: Permission denied

Each find: Failed to change directory: Permission denied is for each file I am trying to move to _lastBackUp

Thanks for any insight into this.

2 Answers 2

2

Looks like the error is about having no permission to change directory.

  • verify that the user has at least r-x on each folder leading down to the path from where the script is executed.
  • verify that the user has at least rwx on the folder + files where the backups are located.
  • verify whether the user has a login shell, $HOME and $PATH. If yes, make the script cd to some relevant location before starting operation. If not, define all commands and locations using absolute paths.

I cannot come up with any other possible causes.

2
  • 1
    Your last option worked (cd to relevant location)! I was in as my user initially and when I sudo su mysqlBackupUser it appears it kept the user in my original directory. It's weird that it would download the files where they belong and the only issue was with creating the tmp directory, especially since I am using absolute pathing. Either way it works now thanks to your last suggestion! thanks!
    – Jeremy
    Jul 22, 2014 at 13:32
  • Cool, I'm glad it worked out.
    – woohooyeah
    Jul 22, 2014 at 23:11
0

If the mkdir is working, which it seems to be, if you run an ls -al over the parent directory who is the owner of the directories? Sounds to me that something is going wrong with permissions somewhere down the line.

1
  • I get: drwxrwxrwx 2 mysqlBackupUser mysqlBackupUser 4096 Jul 21 16:24 _lastBackUp
    – Jeremy
    Jul 21, 2014 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .