Last active
July 28, 2025 07:27
-
-
Save supersonictw/1f145442edee81f9c7a98a3b51f878e3 to your computer and use it in GitHub Desktop.
Execute rustic and sends a notification upon successful completion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# irustic.sh - Execute rustic and sends a notification upon successful completion. | |
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/Kkn2DQsNR) | |
set -e | |
# rustic-rs/rustic | |
# https://github.com/rustic-rs/rustic | |
DIR_RUSTIC="/root/.config/rustic" | |
DIR_IRUSTIC="/root/.local/bin" | |
FILE_RUSTIC_CFG="$DIR_RUSTIC/rustic.toml" | |
FILE_IRUSTIC_SH="$DIR_IRUSTIC/irustic.sh" | |
# setup rustic | |
mkdir -p "$DIR_RUSTIC" | |
touch "$FILE_RUSTIC_CFG" | |
chmod 0600 "$FILE_RUSTIC_CFG" | |
chown root:root "$FILE_RUSTIC_CFG" | |
# setup irustic | |
mkdir -p "$DIR_IRUSTIC" | |
touch "$FILE_IRUSTIC_SH" | |
chmod 0700 "$FILE_IRUSTIC_SH" | |
chown root:root "$FILE_IRUSTIC_SH" | |
# setup rustic.toml | |
tee -a "$FILE_RUSTIC_CFG" <<'EOF' | |
[repository] | |
repository = "/root/.irustic" | |
password = "irustic_password" # openssl rand -hex 18 | |
[forget] | |
keep-hourly = 20 | |
keep-daily = 14 | |
keep-weekly = 8 | |
keep-monthly = 24 | |
keep-yearly = 10 | |
[[backup.snapshots]] | |
sources = ["/root"] | |
[[backup.snapshots]] | |
sources = ["/home"] | |
[[backup.snapshots]] | |
sources = ["/srv"] | |
[[backup.snapshots]] | |
sources = ["/opt"] | |
EOF | |
echo "Please run init manually after set rustic.toml up:" | |
echo "rustic init" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# irustic.sh - Execute rustic and sends a notification upon successful completion. | |
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/Kkn2DQsNR) | |
# Setup irustic crontab: | |
# crontab -e | |
# 0 */2 * * * /root/.local/bin/irustic.sh >/dev/null 2>&1 # execute silently every 2 hours | |
# define notify function | |
NOTIFY() { | |
DATE_NOW="$(date)" | |
curl \ | |
-X POST \ | |
-H "Content-Type: application/json" \ | |
-d "{\"content\":\"Rustic has been executed at \`$DATE_NOW\`.\"}" \ | |
"$1" | |
} | |
# define notify destination | |
WEBHOOK_DISCORD="https://discordapp.com/api/webhooks/..." | |
# run the task | |
rustic backup | |
# run the notify | |
NOTIFY "$WEBHOOK_DISCORD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment