Created
May 19, 2023 16:46
-
-
Save jorgeteixe/0a61db668da7ca3539782c12c7efca1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# autor: Álvaro Freire Ares | |
# autor: Jorge Teixeira Crespo | |
BACKUP_DIR="/var/backups" | |
while IFS=':' read -r username _ _ _ _ homedir _; do | |
if [ -n "$homedir" ] && [ -f "$homedir/.IWantBackup" ]; then | |
backup_file="${BACKUP_DIR}/$(date +%Y%m%d)_${username}.tar.gz" | |
if [ ! -f "$backup_file" ]; then | |
tar -czf "$backup_file" -C "$(dirname "$homedir")" "$(basename "$homedir")" | |
chmod 600 "$backup_file" | |
chown "$username" "$backup_file" | |
fi | |
fi | |
done </etc/passwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment