Fix backup script
This commit is contained in:
		
							parent
							
								
									e8b1b05ba9
								
							
						
					
					
						commit
						4f78590e8a
					
				
					 1 changed files with 9 additions and 7 deletions
				
			
		| 
						 | 
					@ -9,7 +9,7 @@ set +a
 | 
				
			||||||
duration_start=$(date +%s)
 | 
					duration_start=$(date +%s)
 | 
				
			||||||
_duration_get () {
 | 
					_duration_get () {
 | 
				
			||||||
	duration_end=$(date +%s)
 | 
						duration_end=$(date +%s)
 | 
				
			||||||
	duration=$((duration_end - duration_start))
 | 
						echo "$((duration_end - duration_start))"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
hc_url="https://hc-ping.com/$HC_UID"
 | 
					hc_url="https://hc-ping.com/$HC_UID"
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ _hc_ping () {
 | 
				
			||||||
	curl -fsSL --retry 3 "$hc_url$1" >/dev/null
 | 
						curl -fsSL --retry 3 "$hc_url$1" >/dev/null
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
_uptime_kuma_ping () {
 | 
					_uptime_kuma_ping () {
 | 
				
			||||||
	duration=_duration_get
 | 
						duration=$(_duration_get)
 | 
				
			||||||
	curl -fsSL --retry 3 \
 | 
						curl -fsSL --retry 3 \
 | 
				
			||||||
		--url-query "status=$1" \
 | 
							--url-query "status=$1" \
 | 
				
			||||||
		--url-query "msg=$2" \
 | 
							--url-query "msg=$2" \
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,7 @@ _uptime_kuma_ping () {
 | 
				
			||||||
_fail () {
 | 
					_fail () {
 | 
				
			||||||
	_hc_ping "/fail"
 | 
						_hc_ping "/fail"
 | 
				
			||||||
	_uptime_kuma_ping "down" "$1"
 | 
						_uptime_kuma_ping "down" "$1"
 | 
				
			||||||
 | 
						rm -rf "$BACKUP_LOCATION"
 | 
				
			||||||
	exit 1
 | 
						exit 1
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
_success () {
 | 
					_success () {
 | 
				
			||||||
| 
						 | 
					@ -38,20 +39,21 @@ _success () {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_hc_ping "/start"
 | 
					_hc_ping "/start"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BACKUP_LOCATION="$(mktemp -d)"
 | 
					BACKUP_LOCATION="$(mktemp -d --suffix=-backup)"
 | 
				
			||||||
export BACKUP_LOCATION
 | 
					export BACKUP_LOCATION
 | 
				
			||||||
cd "$BACKUP_LOCATION" || exit
 | 
					cd "$BACKUP_LOCATION" || _fail "failed to cd to $BACKUP_LOCATION"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
shopt -s nullglob
 | 
					shopt -s nullglob
 | 
				
			||||||
for file in "{{ service_path }}/backup.d/"*
 | 
					for file in "{{ service_path }}/backup.d/"*
 | 
				
			||||||
do
 | 
					do
 | 
				
			||||||
 | 
						file_name="$(basename "$file")"
 | 
				
			||||||
	echo ""
 | 
						echo ""
 | 
				
			||||||
	echo "running $file"
 | 
						echo "running $file_name"
 | 
				
			||||||
	time "$file" || _fail "fail while running $file"
 | 
						time "$file" >"/tmp/$file_name.log" || _fail "error while running $file_name"
 | 
				
			||||||
done || true
 | 
					done || true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cd "{{ service_path }}"
 | 
					cd "{{ service_path }}"
 | 
				
			||||||
docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "fail during restic backup"
 | 
					docker compose run --rm -v "$BACKUP_LOCATION:/backup/misc" app backup /backup || _fail "error during restic backup"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_success
 | 
					_success
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue