1

I am using Debian and want to reinstall a backup of personal and configuration files (the entire /home folder of a user) on a new computer.

For some reason I cannot understand, every files of my entire backup has the same permissions : 777 / -rwxrwxrwx. This is way too permissive for some configuration files. For example, the first time I used ssh after reinstalling the backup, I had to do a "chmod 600 ~/.ssh/config" to be able to start ssh.

I really do not know why this happened. I backup with rsync -av with should preserve permissions and my external hard drive is using a ext4 filesystem.

Anyway, I have only this backup and no possibility to make another one (the computer died). I am looking for a way to set files and folder to their default settings (for example I guess .ssh/config file is 600) automatically.

Is there a way to achieve this automatically?

1

Here you go;

ORIG_DIR="/bla/bla"
BKUP_DIR="/bla/dee"
:~$ find $ORIG_DIR | while read aline; do perm=$(stat "$aline" | grep "Access: (" | sed 's/Access: (//;s/\/.*//'); chmod -v $perm "$BKUP_DIR/$aline"; done

I made an example;

:~$ mkdir ooh
:~$ mkdir noo
:~$ touch ooh/mog1 ooh/mog2 ooh/mog3
:~$ rsync -av ooh noo
sending incremental file list
ooh/
ooh/mog1
ooh/mog2
ooh/mog3

sent 245 bytes  received 77 bytes  644.00 bytes/sec
total size is 0  speedup is 0.00
:~$ ls -la noo/ooh/
total 32
drwxr-xr-x 2 mike mike 4096 Oct 28 23:09 .
drwxr-xr-x 3 mike mike 4096 Oct 28 23:10 ..
-rw-r--r-- 1 mike mike    0 Oct 28 23:09 mog1
-rw-r--r-- 1 mike mike    0 Oct 28 23:09 mog2
-rw-r--r-- 1 mike mike    0 Oct 28 23:09 mog3
:~$ chmod 700 ooh/mog1
:~$ chmod 600 ooh/mog2
:~$ chmod 555 ooh/mog3
:~$ find ooh
ooh
ooh/mog1
ooh/mog3
ooh/mog2
:~$ find ooh | while read aline; do perm=$(stat "$aline" | grep "Access: (" | sed 's/Access: (//;s/\/.*//'); chmod -v $perm "noo/$aline"; done
mode of 'noo/ooh' retained as 0755 (rwxr-xr-x)
mode of 'noo/ooh/mog1' changed from 0644 (rw-r--r--) to 0700 (rwx------)
mode of 'noo/ooh/mog3' changed from 0644 (rw-r--r--) to 0555 (r-xr-xr-x)
mode of 'noo/ooh/mog2' changed from 0644 (rw-r--r--) to 0600 (rw-------)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.