Added a script that backups obsidian notes

This commit is contained in:
Tomas Rivera
2026-03-28 10:04:05 +01:00
parent fe5dd2d660
commit 929ee1d060
5 changed files with 83 additions and 16 deletions
+7 -6
View File
@@ -203,6 +203,7 @@ in {
"custom-mountkdrive"
#"waybar"
"custom-gitnotify"
"custom-obsidianbackup" # backups the obsidian notes to kdrive and to a timed hidden dir (~/.Notes.backup/)
"QS-notifycache" # builds the cache that will be used for the notification history
#########################
@@ -353,8 +354,8 @@ in {
"2, layout:scrolling, layoutopt:direction:right"
"name:special, layout:scrolling"
# used for smart gaps along some windowrules
"w[tv1], gapsout:0, gapsin:0"
"f[1], gapsout:0, gapsin:0"
"w[tv1], gapsout:1, gapsin:1"
"f[1], gapsout:1, gapsin:1"
];
# █░█░█ █ █▄░█ █▀▄ █▀█ █░█░█   █▀█ █░█ █░░ █▀▀ █▀
@@ -415,10 +416,10 @@ in {
"float on, size 400 175, match:class ^(custom-librewolfprofiles)$"
"float on, size 600 600, match:initial_class ^(custom-pomodoro)$"
"float on, size 1500 800, match:initial_class ^(custom-bottom)$"
"border_size 0, match:float 0, match:workspace w[tv1]"
"rounding 0, match:float 0, match:workspace w[tv1]"
"border_size 0, match:float 0, match:workspace f[1]"
"rounding 0, match:float 0, match:workspace f[1]"
"border_size 2, match:float 0, match:workspace w[tv1]"
"rounding 1, match:float 0, match:workspace w[tv1]"
"border_size 2, match:float 0, match:workspace f[1]"
"rounding 1, match:float 0, match:workspace f[1]"
];
# add a float for tomato when in kitty
#"plugin:imgborders:noimgborders, tag:noborder"
+9 -2
View File
@@ -7,7 +7,14 @@
enable = true;
vaults.miscellanious = {
enable = true;
#target = "/kdrive/Notes/miscellanious"; #not directly to kdrive. It causes problems
};
target = "/Documents/Notes/miscellanious"; # target is relative to ~ #not directly to kdrive. It causes problems
};
vaults.work = {
enable = true;
target = "/Documents/Notes/work";
};
defaultSettings = {
};
};
}
+64
View File
@@ -0,0 +1,64 @@
{
writeShellApplication,
rclone,
libnotify,
rsync,
...
}:
writeShellApplication {
name = "custom-obsidianbackup";
runtimeInputs = [
rclone
libnotify
rsync
];
text = ''
#!/usr/bin/env bash
SOURCE_DIR="$HOME/Documents/Notes"
DEST_DIR="$HOME/kdrive/Notes"
BACKUP_DIR="$HOME/.Notes.backup"
mkdir -p "$DEST_DIR"
mkdir -p "$BACKUP_DIR"
while true; do
# Timestamp for this run
TIMESTAMP=$(date +%Y-%m-%d_%H-%M)
TIMESTAMPED_BACKUP="$BACKUP_DIR/$TIMESTAMP"
mkdir -p "$TIMESTAMPED_BACKUP"
echo "[$(date)] Starting Obsidian backup..."
# Check rclone mount
status=$(rclone about kdrive: 2>&1 || true)
if [[ "$status" =~ .*CRITICAL.* ]]; then
echo "[$(date)] rclone failed:"
echo "$status"
notify-send -u critical "rclone failed" \
"rclone might be broken or you need to deactivate this script in HomeManager."
else
# Run rsync with verbose debugging
echo "[$(date)] Running rsync..."
rsync -Lavh --progress --update --backup --backup-dir="$TIMESTAMPED_BACKUP" \
--exclude='.obsidian/cache/**' \
"$SOURCE_DIR/" "$DEST_DIR/"
echo "[$(date)] Backup completed for this run."
fi
# Safely remove backups older than 30 days
if [[ -d "$BACKUP_DIR" && "$BACKUP_DIR" == "$HOME/.Notes.backup" ]]; then
echo "[$(date)] Cleaning old backups..."
find "$BACKUP_DIR/" -mindepth 1 -maxdepth 1 -type d -mtime +30 -exec rm -rf {} \;
else
echo "[$(date)] Backup directory not safe. Skipping cleanup."
fi
# Wait 1 hour
echo "[$(date)] Sleeping for 1 hour..."
sleep 3600
done
'';
}