1
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.
1Your 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 – 2014-07-22T13:32:30.740Cool, I'm glad it worked out. – woohooyeah – 2014-07-22T23:11:58.123