singleuser.sh 1.1 KB
Newer Older
Kai Lorenz's avatar
Kai Lorenz committed
1
#!/usr/bin/env bash
2
# Utility Tool to archive a single user account on a standard webis machine
Kai Lorenz's avatar
Kai Lorenz committed
3
# based on https://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/ 
4
# Author: Kai Lorenz
Kai Lorenz's avatar
Kai Lorenz committed
5 6
# Last update 24.02.2019

Kai Lorenz's avatar
Kai Lorenz committed
7 8 9 10 11
if (( EUID != 0 )); then
    echo "Please execute this script as root (sudo su)." 1>&2
    exit 1
fi

Kai Lorenz's avatar
Kai Lorenz committed
12 13 14 15 16 17 18 19
ls /home/
echo "Please enter the target username"
read varTargerUser
read -p "Please confirm, "$varTargerUser" is your target? Y/N " -n 1 -r
echo    # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
	varArchiveName=$({ date +%Y; echo -; hostname; echo -; echo $varTargerUser; } | sed ':a;N;s/\n/ /;ba' | tr -d '[:space:]')
20 21
	mkdir /move
	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
Kai Lorenz's avatar
Kai Lorenz committed
22
	mv -uv /move/$varArchiveName.tar.gz /mnt/nfs/webis20/code-in-archive/account-graveyard
Kai Lorenz's avatar
Kai Lorenz committed
23
fi