Improve vaultwarden backup shell scripting
This commit is contained in:
		
							parent
							
								
									4fe1ef2091
								
							
						
					
					
						commit
						1a1d6685b8
					
				
					 1 changed files with 4 additions and 13 deletions
				
			
		|  | @ -23,23 +23,14 @@ docker exec --env-file "${PASSFILE}" "${database_container}" pg_dump 'vaultwarde | ||||||
| docker cp "${database_container}":"${internal_database_backupfile}" "${BACKUP_DEST}" | docker cp "${database_container}":"${internal_database_backupfile}" "${BACKUP_DEST}" | ||||||
| 
 | 
 | ||||||
| # Files backup | # Files backup | ||||||
| files=('attachments' 'sends' 'config.json' 'rsa_key.pem' 'rsa_key.pub.pem') | for file in 'attachments' 'sends' 'config.json' 'rsa_key.pem' 'rsa_key.pub.pem'; do | ||||||
| for file in "${files[@]}"; do | 	>&2 printf 'Copying %s\n' "${file}" | ||||||
| 	>&2 echo "Copying ${file}" |  | ||||||
| 	docker cp -a "${base_container}":"/data/${file}" "${BACKUP_DEST}" | 	docker cp -a "${base_container}":"/data/${file}" "${BACKUP_DEST}" | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| # Backup cleanup | # Backup cleanup | ||||||
| # Only keep the 30 most recent backups => probably a month worth of backups, seems about right. | # Only keep 30 days of backups, seems about right. | ||||||
| >&2 echo 'Cleaning up old database backups' | >&2 echo 'Cleaning up old database backups' | ||||||
| pushd "${BACKUP_DEST}" | find "${BACKUP_DEST}" -name '*sqlbkp*' -type f -mtime +30 -print # -delete | ||||||
| excess="$( ls -1 | grep sqlbkp | head -n -30 )" |  | ||||||
| if [ -n "${excess}" ]; then |  | ||||||
| 	>&2 echo "Removing ${excess}" |  | ||||||
| 	rm "${excess}" |  | ||||||
| else |  | ||||||
| 	>&2 echo 'Skipping: nothing to remove' |  | ||||||
| fi |  | ||||||
| popd |  | ||||||
| 
 | 
 | ||||||
| >&2 echo 'Done' | >&2 echo 'Done' | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue