use rsync to backup files

This commit is contained in:
Yan Lin 2025-12-05 23:07:12 +01:00
parent dd888c98a0
commit 5a75588042
2 changed files with 16 additions and 38 deletions

View file

@ -17,6 +17,17 @@
]; ];
}; };
services.scheduled-commands.backup-to-thinkpad = {
enable = true;
description = "Backup files to thinkpad";
interval = "*-*-* 00:00:00";
commands = [
"rsync-backup /mnt/storage/appbulk/immich/library/admin thinkpad:~/Backup/photos/immich-library"
"rsync-backup /mnt/storage/Media/DCIM thinkpad:~/Backup/photos/DCIM"
"rsync-backup /mnt/storage/Media/nsfw thinkpad:~/Backup/nsfw"
];
};
home.packages = with pkgs; [ home.packages = with pkgs; [
]; ];

View file

@ -3,39 +3,6 @@
{ {
# Install rsync package # Install rsync package
home.packages = with pkgs; [ rsync exiftool ]; home.packages = with pkgs; [ rsync exiftool ];
# Rsync exclude patterns for common files and directories
home.file.".rsync-exclude".text = ''
'';
# Rsync configuration for common backup scenarios
home.file.".rsync-backup.conf".text = ''
# Common rsync options for backups
# Usage: rsync @backup-options source/ destination/
# Standard backup options
--archive
--verbose
--progress
--human-readable
--exclude-from=~/.rsync-exclude
--delete
--delete-excluded
--partial
--partial-dir=.rsync-partial
${lib.optionalString pkgs.stdenv.isDarwin ''
# Preserve extended attributes and ACLs (macOS)
--extended-attributes
--acls
''}
# Network optimization
--compress
--compress-level=6
# Safety options
--dry-run # Remove this line when you're ready to run for real
'';
programs.zsh.initContent = '' programs.zsh.initContent = ''
function rsync-backup() { function rsync-backup() {
@ -57,7 +24,7 @@
echo "Destination: $DEST" echo "Destination: $DEST"
echo "===================" echo "==================="
rsync $(cat ~/.rsync-backup.conf | grep -v '^#' | grep -v '^$' | tr '\n' ' ') "$SOURCE" "$DEST" rsync -avh --progress --delete --partial --partial-dir=.rsync-partial --compress "$SOURCE" "$DEST"
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Backup completed successfully!" echo "Backup completed successfully!"
@ -133,10 +100,10 @@
''; '';
programs.zsh.shellAliases = { programs.zsh.shellAliases = {
rsync-quick = "rsync -avh --progress --exclude-from=~/.rsync-exclude"; rsync-quick = "rsync -avh --progress";
rsync-dry = "rsync -avh --progress --exclude-from=~/.rsync-exclude --dry-run"; rsync-dry = "rsync -avh --progress --dry-run";
rsync-full = "rsync-backup"; rsync-full = "rsync-backup";
rsync-sync = "rsync -avh --progress --exclude-from=~/.rsync-exclude"; rsync-sync = "rsync -avh --progress";
rsync-mirror = "rsync -avh --progress --exclude-from=~/.rsync-exclude --delete"; rsync-mirror = "rsync -avh --progress --delete";
}; };
} }