5 November 2026 · Practical AI builds
How do I back up a small AI app and its data on a VPS?
By the end of this you will have a nightly, encrypted copy of your AI app, its database and its uploaded files, stored away from the server it runs on. You will also have checked that you can get it back. It suits anyone running one small app on one VPS, such as a chatbot, an FAQ bot or a document tool, who would lose real work if that server broke.
I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.
What you need
- SSH access to your VPS with a user that can read the app's folders (often root or a user with sudo).
- A backup tool that encrypts and only uploads what has changed. I use restic, which is free and open source and is in the Ubuntu package list.
- Somewhere else to store the copy. An S3-compatible storage bucket from a cloud provider works well, and most providers charge by the amount stored. A second small server reached over SFTP also works.
- The database's own dump tool, for example
pg_dumpfor Postgres ormysqldumpfor MySQL. - A password manager, to keep the backup password somewhere that is not the server.
Step by step
- Make a list of what the app cannot live without: the code folder, the
.envor config file, uploaded files, any vector store or index the AI reads from, the database, and the nginx and PM2 or Docker Compose files that start it. - Install restic with
sudo apt install resticand create a bucket or folder at your storage provider, with a key that can only reach that one bucket. - Create a password for the backup, save it in your password manager, then put it in a file only root can read, such as
/root/.restic-passwith permissions 600. Without this password the backup cannot be opened by anyone, including you. - Set up the backup store once with
restic init, pointing it at your bucket. Restic will refuse to start if the password file or storage keys are wrong, which is a useful early check. - Dump the database to a plain file first, rather than copying the live database files while the app is writing to them. If you have not done this before, see how to back up a Postgres database from the command line.
- Write a short script that does the dump, then the backup, then tidies up old copies. A simple version looks like this:
#!/bin/sh set -e export RESTIC_REPOSITORY=s3:https://s3.example.com/appname-backups export RESTIC_PASSWORD_FILE=/root/.restic-pass export AWS_ACCESS_KEY_ID=yourkeyid export AWS_SECRET_ACCESS_KEY=yoursecret pg_dump -U appuser appname > /var/backups/appname/db.sql restic backup /var/backups/appname /srv/appname /etc/nginx restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune - Make the script readable only by root (
chmod 700), since it holds storage keys, and run it once by hand to make sure it finishes without errors. - Schedule it every night with cron, sending the output to a log so you can see what happened:
0 3 * * * /usr/local/bin/backup-appname.sh >> /var/log/backup-appname.log 2>&1 - Test a restore into a spare folder with
restic restore latest --target /tmp/restore-test, open a few files, and load the database dump into a test database to check it is complete. - Put a reminder in your calendar to repeat that restore test every month or two.
What good looks like
Running restic snapshots shows one new snapshot every night, the log ends without errors, and the storage bucket grows slowly rather than by the full size of your app each time. Most importantly, you have restored a copy into a test folder, started the app from it or loaded its database, and seen your own data come back as it should.
Watch out for
The most common mistake is a backup that has never been restored. It might be missing the database, the config file or the folder where uploads really live, and you only find out on the bad day. If your app runs in Docker, its data may sit in a Docker volume rather than a folder you expected, so dump the database from inside the container (for example with docker exec) and check which volumes hold files. Also remember that backups hold everything your app holds: customer messages, uploaded documents and API keys. Keep them encrypted, keep the storage keys limited to that one bucket, and delete old copies on a schedule so you are not keeping personal data longer than you need to.
Questions people ask
Are my hosting provider's snapshots enough on their own?
They are a useful extra, but they usually live with the same provider and sometimes in the same data centre, so a billing problem or account lockout can take them too. A second copy somewhere else, under your own control, covers that.
Do I need to back up the AI model itself?
Usually not. If you call a model through an API, there is nothing to copy, and if you run an open model locally you can download it again. Back up your prompts, settings, documents and any index you built from them, because those are yours and harder to rebuild.
In short: dump the database, let restic copy the dump and the app's folders to encrypted storage somewhere else every night, keep a sensible number of old copies, and prove it works by restoring it now and then.
You can get the same kind of VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.
Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.
Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.
Affiliate link.