Strategies for offsite backups?

I was hoping to use Tarsnap to externally backup the data on some of my apps/volumes. I imagine I could achieve this in a semi-roundabout way by writing a script that leverages flyctl to ssh into each app, install tarsnap if it isn’t there, and finally list and backup the volumes.

Any issues with this approach? Other ideas people have implemented?

I made a separate vm in each org to run backups. Another alternative, you could also just install tarsnap into every docker image and have a cron job for the volumes run in the vm.

I think it’d be cool to ask Fly to support exporting and importing volume snapshots


Edit: flyctl import / export volume snapshots · Issue #1296 · superfly/flyctl · GitHub

1 Like

Could you possibly elaborate or link to how your backup VM works? I imagine it’s a service that connects to running fly apps and follows roughly the same process I described for a theoretical script, but I would be interested to see exactly how you solved it in practice

I’ve cut and paste the trickiest partswhich was getting cron to run reliably and s3 cleanup.


#FROM debian:bullseye-20220711-slim
FROM postgres:14.4-bullseye

RUN apt-get update -y && apt-get install -y postgresql-client zstd s3cmd s3fs cron busybox   \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*

RUN mkdir -p /backup/
WORKDIR /backup
COPY --chmod=0755 dump.sh /backup
COPY --chmod=0600 s3cfg /root/.s3cfg

ENTRYPOINT ["/entrypoint.sh"]
CMD ["cron", "-L", "15",  "-f"]
COPY --chmod=0755 entrypoint.sh /

Entrypoint.sh

#!/usr/bin/env bash
set -euo pipefail

echo "Generating cron schedules"
echo "${BACKUP_SCHEDULE} /backup/dump.sh" >> /root/backup_schedule
crontab /root/backup_schedule
exec "$@"

And s3 cleanup segment

expiry="90 days"
s3cmd ls s3://${ORG}-backup | while read -r line;
  do
    createDate=`echo $line|awk {'print $1" "$2'}`
    createDate=`date -d"$createDate" +%s`
    olderThan=`date -d"-${expiry}" +%s`
    if [[ $createDate -lt $olderThan ]]
      then
        fileName=`echo $line|awk {'print $4'}`
        echo $fileName
        if [[ $fileName != "" ]]
          then
            s3cmd del "$fileName"
        fi
    fi
  done;

3 Likes