-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-script.sh
52 lines (42 loc) · 1.72 KB
/
backup-script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Prerequisites:
# - rsync
# - inotify-tools
# Directories for backup (Update these to match your setup)
DIR_LNBITS="/path/to/lnbits/data"
DIR_CASHU="/path/to/cashu/data/mint/"
# Directories for monitoring database changes (Update these to match your setup)
DIR_LNBITSDATA="/path/to/lnbits/data"
DIR_CASHUDATA="/path/to/cashu/data"
# Local and remote destination directories (Update these to match your setup)
DIR_BACKUP_LOCAL_LNBITS="/path/to/local/backups/lnbits"
DIR_BACKUP_LOCAL_CASHU="/path/to/local/backups/cashu"
DIR_BACKUP_REMOTE_LNBITS="[email protected]:/path/to/remote/backups/lnbits"
DIR_BACKUP_REMOTE_CASHU="[email protected]:/path/to/remote/backups/cashu"
# Destination directory names (Optional: Update if desired)
DIRNAME_LNBITS="lnbits-backup"
DIRNAME_CASHU="cashu-backup"
# Backup function
backup() {
rsync -av --delete --update "$DIR_LNBITS" "$DIR_BACKUP_LOCAL_LNBITS/$DIRNAME_LNBITS"
rsync -av --delete --update "$DIR_CASHU" "$DIR_BACKUP_LOCAL_CASHU/$DIRNAME_CASHU"
rsync -av --delete --update "$DIR_LNBITS" "$DIR_BACKUP_REMOTE_LNBITS/$DIRNAME_LNBITS"
rsync -av --delete --update "$DIR_CASHU" "$DIR_BACKUP_REMOTE_CASHU/$DIRNAME_CASHU"
if [ $? -eq 0 ]; then
echo "Backup successfully completed on $(date)"
else
echo "Error performing backup on $(date)"
fi
}
# Minimum time between backups (in seconds)
MIN_INTERVAL=30
LAST_RUN=0
# Monitor directory changes and execute backup
inotifywait -m -r -e modify,create,delete,move "$DIR_LNBITSDATA" "$DIR_CASHUDATA" | while read path action file; do
NOW=$(date +%s)
if (( NOW - LAST_RUN > MIN_INTERVAL )); then
echo "Detected change in $path$file due to $action"
backup
LAST_RUN=$NOW
fi
done