all.sh 1.01 KB
Newer Older
1 2 3 4 5
#!/usr/bin/env bash
# Utility Tool to archive all user accounts on a standard webis machine
# based on https://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/
# Author: Kai Lorenz 
# Last update 07.03.2019
6 7
sudo su 
mkdir /move
8 9 10 11 12 13 14
cd /home/ || exit
for f in */; do
    # do some stuff here with "$f"
    # remember to quote it or spaces may misbehave
    varTargerUser="$f"
    if [[ $varTargerUser != *"webis"* ]];then
	    varArchiveName=$({ date +%Y; echo -; hostname; echo -; echo $varTargerUser; } | sed ':a;N;s/\n/ /;ba' | tr -d '[:space:]')
15 16 17
	    apt-get autoremove -y
		tar --exclude='/home/$varTargerUser/.local/share/Trash/' --exclude='/home/$varTargerUser/.cache/mozilla' --exclude='/home/$varTargerUser/.wine' --exclude='/home/$varTargerUser/.cache/google-chrome' --exclude='/home/$varTargerUser/.cache/pip' --exclude='/home/$varTargerUser/.cache/thumbnails' -zcvpf /move/$varArchiveName.tar.gz /home/$varTargerUser
		mv -uv /move/* /mnt/nfs/webis20/code-in-archive/account-graveyard
18 19 20
	fi
    
done