I have a root cron
job which creates a directory in a mounted different HDD and then using rsync
I am copying all files from SOURCE to TARGET. Script looks like this:
date_cmd='date +%Y_%m_%d_%H_%M_%S'
TS_SUFFIX=`eval ${date_cmd}`
SOURCE_DIR=/
TARGET_DIR=/mnt/backup_hdd/system_backup_${TS_SUFFIX}
LOG_DIR=/shared_utils/logs/backupper
LOG_FILE=${LOG_DIR}/backupper_${TS_SUFFIX}.log
mkdir -p ${TARGET_DIR}
chmod 770 ${TARGET_DIR}
rsync -a --append-verify --info=progress2 --exclude-from=${EXCLUDE_LIST} ${SOURCE_DIR} ${TARGET_DIR}
The problem is that chmod 770
doesn't change the TARGET
dir permisisons to 770. As you see it is created with 755 permissions.:
drwxr-xr-x 19 root root 4096 Mar 18 11:47 system_backup_2018_03_18_17_57_01/
My root cron
job:
57 17 * * * umask 007; /path/to/script.sh
As you see I set umask 007 before executing the script. So, it fails on 2 fronts:
- Although I am setting the umask to
007
, the actual permissions are not as expected. - Although I am explicitly changing permissions(
chmod 770
) to theTARGET
dir, permissions are still not changed.
Any ideas why these 2 cases don't work?
UPDATE
Running the script with sudo script.sh
doesn't change the permissions of TARGET
, either.
cron
? I suspect thersync -a
to set the permissions similar to the source directory.rsync
command, the permissions were set correctly. Seemsrsync
overwrites them..stat --printf "%a" /
.chmod
andrsync
.