Skip to content

Instantly share code, notes, and snippets.

@jorgeteixe
Created May 19, 2023 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeteixe/0a61db668da7ca3539782c12c7efca1f to your computer and use it in GitHub Desktop.
Save jorgeteixe/0a61db668da7ca3539782c12c7efca1f to your computer and use it in GitHub Desktop.
#!/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