0

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:

  1. Although I am setting the umask to 007, the actual permissions are not as expected.
  2. Although I am explicitly changing permissions(chmod 770) to the TARGET 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.

6
  • 1
    Does it work without cron? I suspect the rsync -a to set the permissions similar to the source directory.
    – PerlDuck
    Mar 18, 2018 at 17:31
  • @PerlDuck Nope. I will update question :)
    – CuriousGuy
    Mar 18, 2018 at 17:34
  • @PerlDuck Seems you are right. When commented the rsync command, the permissions were set correctly. Seems rsync overwrites them..
    – CuriousGuy
    Mar 18, 2018 at 17:39
  • Show output of stat --printf "%a" /.
    – Cyrus
    Mar 18, 2018 at 17:40
  • 2
    Swap chmod and rsync.
    – Cyrus
    Mar 18, 2018 at 17:41

1 Answer 1

0

Thanks to PerlDuck and Cyrus the mystery is solved.

rsync -a creates the TARGET dir with the same permissions as the SOURCE(in my case 755).

You must log in to answer this question.

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