diff --git a/home-manager/home.nix b/home-manager/home.nix index a073284..578fa4d 100644 --- a/home-manager/home.nix +++ b/home-manager/home.nix @@ -84,6 +84,7 @@ in vlc jellyfin-media-player syncterm + tradingview ]; programs.starship = { diff --git a/kopiascript.sh b/kopiascript.sh new file mode 100644 index 0000000..7620977 --- /dev/null +++ b/kopiascript.sh @@ -0,0 +1,50 @@ + +# Ensure Kopia is in the PATH for systemd execution +PATH=/run/current-system/sw/bin:$PATH + +# Exit on error +set -e + +LOG_TAG="kopia-backup-nixos-server" + +# --- Configuration --- +# Add full paths to directories you want to back up +DIRECTORIES_TO_BACKUP=( + "/etc" + "/srv" + "/var/log" + "/home/" + "/var/lib/" + "/root/" + "/storage" + # Be specific for home directories if not backing up all of /home + # Add more paths as needed +) + +# --- Backup Logic --- +logger -t "$LOG_TAG" "Starting Kopia backup process for NixOS server." + +# Connect to repository (Kopia will use existing config if already connected and valid) +# This is a safety check; normally not needed if `kopia repository connect` was successful earlier. +# If you encounter issues, you might need to ensure the environment for systemd can find the kopia config. +# For simplicity, we assume the `sudo kopia repository connect` in Step 2 established the connection. + +for dir_path in "${DIRECTORIES_TO_BACKUP[@]}"; do + if [ -d "$dir_path" ]; then + logger -t "$LOG_TAG" "Backing up directory: $dir_path" + # The username and hostname from the 'connect' command will be used by default. + # You can add specific tags for better organization. + kopia snapshot create "$dir_path" --tags "path:$dir_path" + logger -t "$LOG_TAG" "Successfully backed up: $dir_path" + else + logger -t "$LOG_TAG" "Directory not found, skipping: $dir_path" + fi +done + +logger -t "$LOG_TAG" "Kopia backup process completed." + +# Optional: Run Kopia maintenance (can also be a separate timer) +# logger -t "$LOG_TAG" "Running Kopia maintenance." +#kopia maintenance run --full +#logger -t "$LOG_TAG" "Kopia maintenance finished." + diff --git a/modules/nixos/laptop/backup.nix b/modules/nixos/laptop/backup.nix index 184668f..8669b87 100644 --- a/modules/nixos/laptop/backup.nix +++ b/modules/nixos/laptop/backup.nix @@ -3,28 +3,31 @@ config, ... }: { - # agenix - age.secrets.restic-hetzner.file = ../../secrets/restic-hetzner.age; - age.secrets.restic-hetzner-password.file = ../../secrets/restic-hetzner-password.age; + - # ssh known hosts - programs.ssh.knownHosts = { - "u419690.your-storagebox.de".publicKey = ""; - }; + services.restic.backups = { remotebackup = { + exclude = [ + *cache + ] initialize = true; paths = [ # what to backup - "/persistent" - ]; - passwordFile = config.age.secrets.restic-hetzner-password.path; # encryption - repository = "sftp://-@.your-storagebox.de/"; @ where to store it - - extraOptions = [ - # how to connect - "sftp.command='${pkgs.sshpass}/bin/sshpass -f ${config.age.secrets.restic-hetzner.path} -- ssh -4 u419690.your-storagebox.de -l u419690-sub1 -s sftp'" + "/etc" + "/srv" + "/var/log" + "/home" + "/var/lib" + "/root" + "/storage" ]; + passwordFile = "/etc/nixos/secrets/restic-password"; # encryption + repository = "s3:s3.idrivee2.com/your-bucket-name"; # where to store it + environment = { + AWS_ACCESS_KEY_ID = "/etc/nixos/secrets/restic-s3-access-key-id"; + AWS_SECRET_ACCESS_KEY = "/etc/nixos/secrets/restic-s3-secret-access-key"; + }; timerConfig = { # when to backup OnCalendar = "00:05"; RandomizedDelaySec = "5h";