ntfy: integrate notifications into backup script
							parent
							
								
									9b29e68378
								
							
						
					
					
						commit
						b5e9afe5a4
					
				
							
								
								
									
										14
									
								
								nas.yml
								
								
								
								
							
							
						
						
									
										14
									
								
								nas.yml
								
								
								
								
							| 
						 | 
					@ -7,13 +7,6 @@
 | 
				
			||||||
    - common
 | 
					    - common
 | 
				
			||||||
  tags: base
 | 
					  tags: base
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- hosts: nas
 | 
					 | 
				
			||||||
  become: yes
 | 
					 | 
				
			||||||
  roles:
 | 
					 | 
				
			||||||
    - ntfy
 | 
					 | 
				
			||||||
    - ntfy-server
 | 
					 | 
				
			||||||
  tags: ntfy
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
- name: Configure BTRFS RAID
 | 
					- name: Configure BTRFS RAID
 | 
				
			||||||
  hosts: nas
 | 
					  hosts: nas
 | 
				
			||||||
  become: yes
 | 
					  become: yes
 | 
				
			||||||
| 
						 | 
					@ -21,6 +14,13 @@
 | 
				
			||||||
    - raid
 | 
					    - raid
 | 
				
			||||||
  tags: raid
 | 
					  tags: raid
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- hosts: nas
 | 
				
			||||||
 | 
					  become: yes
 | 
				
			||||||
 | 
					  roles:
 | 
				
			||||||
 | 
					    - ntfy
 | 
				
			||||||
 | 
					    - ntfy-server
 | 
				
			||||||
 | 
					  tags: ntfy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- name: Set up Samba
 | 
					- name: Set up Samba
 | 
				
			||||||
  hosts: nas
 | 
					  hosts: nas
 | 
				
			||||||
  become: yes
 | 
					  become: yes
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,10 +8,36 @@
 | 
				
			||||||
export RESTIC_REPOSITORY='rest:http://{{ groups['nas'][0] }}:8000/backups'
 | 
					export RESTIC_REPOSITORY='rest:http://{{ groups['nas'][0] }}:8000/backups'
 | 
				
			||||||
export RESTIC_PASSWORD_FILE='/etc/backups/restic_backups_passwd'
 | 
					export RESTIC_PASSWORD_FILE='/etc/backups/restic_backups_passwd'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					log_file='/tmp/backup-all.sh.log'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rm -f "$log_file"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for script in $(find /etc/backups -name '*.backup.sh'); do
 | 
					for script in $(find /etc/backups -name '*.backup.sh'); do
 | 
				
			||||||
 | 
					    T="$(date +%s)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /usr/bin/bash "$script"
 | 
					    /usr/bin/bash "$script"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    res="$?"
 | 
				
			||||||
 | 
					    T="$(($(date +%s)-T))"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if [[ $res == 0 ]]; then
 | 
				
			||||||
 | 
					        header='OK'
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        header="FAIL ($res)"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf \
 | 
				
			||||||
 | 
					        "%s: %s in %02dh%02dm%02ds\n" \
 | 
				
			||||||
 | 
					        "$(basename "$script")" "$header" \
 | 
				
			||||||
 | 
					        "$((T/3600%24))" "$((T/60%60))" "$((T%60))" \
 | 
				
			||||||
 | 
					        >> "$log_file"
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Prune older backups
 | 
					# Prune older backups
 | 
				
			||||||
/usr/local/bin/restic forget --keep-last 7 && \
 | 
					/usr/local/bin/restic forget --keep-last 7 && \
 | 
				
			||||||
    /usr/local/bin/restic prune
 | 
					    /usr/local/bin/restic prune
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Send status notification
 | 
				
			||||||
 | 
					ntfy publish \
 | 
				
			||||||
 | 
					    --title "Backups ($(hostname))" \
 | 
				
			||||||
 | 
					    homelab "$(cat "$log_file")"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue