SRC="/var/www/myapp"
DEST="/backups"
STAMP="$(date -u +%Y%m%d-%H%M%S)"
mkdir -p "$DEST"
# gzip (fast, decent ratio)
tar -czf "$DEST/myapp-$STAMP.tar.gz" -C "$(dirname "$SRC")" "$(basename "$SRC")"
# xz (best ratio, slow)
tar -cJf "$DEST/myapp-$STAMP.tar.xz" -C "$(dirname "$SRC")" "$(basename "$SRC")"
# Exclude noisy paths
tar -czf "$DEST/myapp-$STAMP.tar.gz" \
--exclude='node_modules' --exclude='.git' --exclude='*.log' \
-C /var/www myapp
# Verify it
tar -tzf "$DEST/myapp-$STAMP.tar.gz" | head
# Keep only the 7 most recent backups
ls -1t "$DEST"/myapp-*.tar.gz | tail -n +8 | xargs -r rm --
Create a free account and build your private vault. Share publicly whenever you want.