#!/run/current-system/sw/bin/fish set BKG_DIR $BKG_DIR set EXCLUDE_APPS $EXCLUDE_APPS set EXCLUDE_VOLUMES $EXCLUDE_VOLUMES set EXCLUDE_CLEANUP $EXCLUDE_CLEANUP set DAYS $DAYS # how many days should daily backups be stored set DF $DF # folder name for daily backups set WF $WF # folder name for weekly backups set MF $MF # folder name for monthly backups set MBD $MBD # day of month for monthly backup set WBD $WBD # weekday for weekly backups set PV $PV # folder name for podman volumes set PODMAN_VOLUMES (podman volume ls --format '{{.Name}}') # if you are using docker just replace the podman command with the docker command if not test -d $BKG_DIR mkdir $BKG_DIR end cd $BKG_DIR # Podman volume backup if not test -d $BKG_DIR/$PV mkdir $BKG_DIR/$PV end for vol in $PODMAN_VOLUMES if contains $vol $EXCLUDE_VOLUMES continue end cd $BKG_DIR/$PV podman volume export $vol --output $vol.tar ; gzip $vol.tar # If you are using docker things look a bit more complicated / comment the podman line and uncomment the following # docker run --rm -v .:/backup -v $vol:/$vol busybox sh -c "cd /$vol && tar cf /backup/$vol.tar . && gzip /backup/$vol.tar" end set BACKUP_APPS (fd . -td -d 1 $BKG_DIR) # App backup for bkg in $BACKUP_APPS if contains $bkg $EXCLUDE_APPS continue end cd $bkg #monthly if not test -d $MF mkdir $MF end set DOM (date +%d) if test $DOM -eq $MBD fd . -tf -d 1 -x cp {/} $MF/(date +"%Y%m")-{/} end #weekly if not test -d $WF mkdir $WF end set DOW (date +%u) if test $DOW -eq $WBD fd . -tf -d 1 -x cp {/} $WF/(date +"%U%Y")-{/} end #dailies if not test -d $DF mkdir $DF end fd . -tf -d 1 -x mv {/} $DF/(date +"%Y%m%d")-{/} end # Delete old backups for bkg in $BACKUP_APPS if contains $bkg $EXCLUDE_CLEANUP continue end fd . $bkg$DF --changed-before $DAYS"d" -X rm fd . $bkg$WF --changed-before "4w" -X rm fd . $bkg$MF --changed-before "8w" -X rm end