Backing Up a Self-Hosted App Properly
The trade in self-hosting is control for responsibility, and backups are where that trade gets settled. A SaaS vendor has a team doing this. On your own server, it is a cron job you wrote once and have not thought about since.
The good news is that a small app like a time tracker is one of the easiest things in the world to back up properly. It is a database and a directory.
What actually needs copying
The database. This is nearly everything: projects, tasks, entries, users, settings. Use the database’s own dump tool rather than copying files from disk — mysqldump or pg_dump produce a consistent snapshot, whereas copying live data files gives you a corrupt one if a write lands mid-copy.
The uploads or storage directory. Anything users attached. Plain file copy is fine.
The configuration. The .env file, the web server config, the cron entries. Small, easy to forget, and the thing that turns a two-hour restore into a two-day one because nobody remembers what the SMTP settings were.
Not the application code. That is in git, or it is a release you can download again. Backing it up wastes space and, worse, encourages restoring old code alongside old data.
A backup that fits in a cron job
#!/bin/sh
set -eu
DEST=/var/backups/app/$(date +%F)
mkdir -p "$DEST"
mysqldump --single-transaction --quick app_db | gzip > "$DEST/db.sql.gz"
tar czf "$DEST/storage.tar.gz" -C /opt/app storage
cp /opt/app/.env "$DEST/env"
find /var/backups/app -maxdepth 1 -type d -mtime +30 -exec rm -rf {} +
--single-transaction gets a consistent dump without locking the tables. set -eu means the script stops on the first failure instead of cheerfully producing an empty archive. The find at the end is the retention policy.
Run it nightly. For a small team’s time tracker, losing at most one day is usually an acceptable worst case; if it is not, run it hourly, because the dump takes seconds.
The rule that makes it a backup
A copy on the same server is not a backup. It survives a deleted table. It does not survive a failed disk, a compromised host, a mistaken rm -rf, or the provider closing your account.
Get it off the machine. rsync over SSH to another box, or rclone to object storage, as a second step after the dump:
rclone copy /var/backups/app/$(date +%F) remote:app-backups/$(date +%F)
Ideally the remote credentials should be write-only, so that a compromise of the server cannot delete the history it just uploaded.
The step everyone skips
Restore it. Not someday — this month, onto a scratch server or a local container.
Untested backups fail in mundane, predictable ways: the dump was empty because the password changed, the archive only contained the directory entry, the cron job has been failing silently since a path moved in April. None of these announce themselves. All of them are discovered at the worst possible time.
Do a full restore twice a year, write down how long it took, and keep that number. It is your actual recovery time, as opposed to the one you assume.
Know your two numbers
How much data can you afford to lose? That sets the backup frequency.
How long can you be down? That sets how rehearsed the restore needs to be. If the answer is “a day”, a documented manual process is fine. If it is “an hour”, write the restore script now, while nothing is on fire.
For a self-hosted time tracker, most teams land on “a day of data, a few hours of downtime”, and that is comfortably handled by the script above plus one offsite copy.
Timecrack is a standard PHP application with a single database — the installation guide covers the layout, and the demo instance shows what you would be restoring.
Need Professional Help?
Get custom development, managed hosting, data migration, and technical support — directly from the creators of Timecrack.
Explore Premium