-1

I have autofs mounted shared /home directories setup on server and it is working perfectly, when i need dir, it is mounted automaticly, when i dont, it is not present. But now i am working on backup scripts and noticed something weird.

In every backup i take, the /home folder on the backup is always empty, or i mean there are no directories in the /home directory. This is due to the fact that when i am taking a snapshot which i later copy, at that time there are no user directories mounted and therefor they are not included in backup, any suggestions how to fix this problem?

Nanoni
  • 123
  • 6
  • The backup of the home directories should be taken on the NFS server, not on a client. – Jenny D Aug 19 '17 at 14:03
  • Ideally yes, and it is infact. NFS server is on 200tb Qnap nas system, which is mirrored to another identical nas system, 1 online and in use, 1 is for full backup of the other. But I want to have seperate rdiff-incremental backup for it aswell. I made a quick and dirty fix for my problem by adding "cd /home/ sleep 5" before running backup part of the my script. This wakes up the /home/user and stays mounted for the duration of the backup, but this obvioulsy isnt the right solution. everytime i create a new user, i have to add that users /home to the script. not a optimal solution! – Nanoni Aug 20 '17 at 15:17
  • Are the users in /etc/passwd? If so, you could run that through sed to pick out the usernames and loop through them; then you won't have to keep a separate list of usernames in the script. – Jenny D Aug 20 '17 at 16:54
  • (I still think this isn't a good way to go about it; taking backups of NFS-mounted systems are not the recommended way to go about it. But I do see your point.) – Jenny D Aug 20 '17 at 16:55
  • Ah yes ofc, why didnt i think of that :) havent used sed before so ill stick with awk, but yes, this is the solution, ill just pick usernames that have id between 1000 and 1050 should be enough. thank you! – Nanoni Aug 20 '17 at 20:05
  • Ok, creating a script to wake up / diretories did force automount on the directories, but they are still not included in the backup for somereason. I increased autofs --timeout 600, then manually woke all /user directories then tried backup, but even then they arent included in the backup. Is there something blocking the backup for a utofs / nfs mounted /dirs? i am using rdiff-backup for the backup job, mayby this is rdiff-backup specific problem, i dont know, havent managed to find any info on this yet. – Nanoni Aug 22 '17 at 07:14
  • 1
    That sounds like it should be a separate question, and you should include details on how you run rdiff in that question. – Jenny D Aug 22 '17 at 07:39

1 Answers1

1

Instead of adding each username to a script, you can have the script go through /etc/passwd and pick out all users whose home directory is on the automount path, and cd to them. Example:

for DIR in `cut -d: -f6 /etc/passwd | grep ^/home/`; do cd "$DIR"; done

cut -d: -f6 will pick out the 6th field, using : as a delimiter, from /etc/passwd. That will give you a list of all home directories. Piped through grep^/home/`, it will give you only those that are mounted under /home.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
  • copy paste of this, did not print all "real" users and printed also syslog and ntp users. Modyfied version that works for me atlest: for line in `awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd`; do ls /home/"$line"; done this prints all uses and does "ls" for each user so AUTOFS mounts user /homes. – Nanoni Aug 21 '17 at 09:05