I recently put together a simple backup system in Bash that pushes my backups to Dropbox
Yesterday was a bit chaotic — my laptop, specifically Firefox, started acting up. Today, thankfully, everything’s stable again. But I wanted to continue this story because there were a few important moments worth sharing: how I managed to recover my tabs, and how that whole situation pushed me to build my own backup system. Honestly, I got pretty lucky. Being able to restore my tabs felt like a small miracle, and building my own backup solution turned into a surprisingly valuable experience. It’s one thing to try a new programming language once and forget it — it’s something else entirely to actually use it to solve a real problem.
So, about recovery. I managed to restore my tabs and parts of my browsing history, though I wasn’t entirely sure how everything came back. The history part made sense — I had Firefox Sync enabled, so once I logged back in, it pulled some data from my account. But the tabs were the real surprise. I use the Simple Tab Groups extension, and it turns out it had been quietly backing up my tab groups all along. That’s what saved me. I was able to recover tabs I had accumulated over the last four years.
After that crash, I realized I don’t want to rely on luck again. That’s when I decided to build my own backup system. This is actually my first Bash script — before this, I’d only heard about Bash but never built anything with it. Initially, I focused on backing up Firefox configs, but then it clicked: I could extend this to cover everything important. Now it backs up my configs, documents, SSH keys, and more — all automatically, without relying on third-party tools. For personal use, it feels solid, though I’m still figuring out how effective it really is long-term. Either way, I like it, and I’m motivated to keep improving it.
#!/bin/bash
set -e
echo "Starting full backup..."
BASE="$HOME/Dropbox/Backups"
DATE=$(date +"%Y-%m-%d_%H-%M")
# Sources
FIREFOX_SRC="/firefox"
KDBX_SRC="$HOME/documents"
SSH_SRC="$HOME/.ssh"
CONFIGS_SRC="$HOME/configs"
# Dest folders
FIREFOX_DIR="$BASE/firefox"
KDBX_DIR="$BASE/passwords"
SSH_DIR="$BASE/ssh"
CONFIGS_DIR="$BASE/configs"
mkdir -p "$FIREFOX_DIR" "$KDBX_DIR" "$SSH_DIR" "CONFIGS_DIR"
# -------------------------
# Firefox backup
# -------------------------
echo "Backing up Firefox..."
TMP_DIR=$(mktemp -d)
rsync -a "$FIREFOX_SRC/" "$TMP_DIR/firefox"
FIREFOX_ARCHIVE="$FIREFOX_DIR/firefox-$DATE.tar.gz"
tar -czf "$FIREFOX_ARCHIVE" -C "$TMP_DIR" firefox
rm -rf "$TMP_DIR"
# keep only last 4 backups
ls -1t "$FIREFOX_DIR"/firefox-*.tar.gz 2>/dev/null | tail -n +5 | xargs -r rm -f
# -------------------------
# Password DB backup
# -------------------------
echo "Backing up password database..."
KDBX_ARCHIVE="$KDBX_DIR/passwords-$DATE.KZN"
cp "$KDBX_SRC" "$KDBX_ARCHIVE"
ls -1t "$KDBX_DIR"/passwords-*.KZN 2>/dev/null | tail -n +5 | xargs -r rm -f
# -------------------------
# Configs backup
# -------------------------
echo "Backing up configs..."
CONFIG_ARCHIVE="$CONFIGS_DIR/configs-$DATE.tar.gz"
tar -czf "$CONFIG_ARCHIVE" -C "$HOME" ".config" 2>/dev/null || true
ls -1t "$CONFIGS_DIR"/configs-*.tar.gz 2>/dev/null | tail -n +5 | xargs -r rm -f
# -------------------------
# SSH keys backup (ENCRYPTED)
# -------------------------
echo "Backing up SSH keys (encrypted)..."
SSH_ARCHIVE_TMP="$SSH_DIR/ssh-$DATE.tar.gz"
SSH_ARCHIVE="$SSH_ARCHIVE_TMP.gpg"
tar -czf "$SSH_ARCHIVE_TMP" -C "$HOME" ".ssh"
gpg --batch --yes \
--passphrase-file "$HOME/backup_system/.backup_gpg_pass" \
--symmetric \
--cipher-algo AES256 \
"$SSH_ARCHIVE_TMP"
rm "$SSH_ARCHIVE_TMP"
# keep only last 4 SSH backups
ls -1t "$SSH_DIR"/ssh-*.tar.gz.gpg 2>/dev/null | tail -n +5 | xargs -r rm -f
# -------------------------
# Telegram notification
# -------------------------
BOT_TOKEN="telegram_token_id"
CHAT_ID="telegram_chat_id"
MSG="Backup SUCCESS on $(date)"
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d chat_id="$CHAT_ID" \
-d text="$MSG"The script itself is pretty straightforward. It defines a set of source directories and destination folders inside my Dropbox backup directory. It then archives everything with timestamps and keeps only the most recent backups to avoid clutter. Once the files land in the Dropbox folder, syncing takes care of the rest automatically.
One thing I paid special attention to was security. When I got to backing up my .ssh directory, I realized I couldn’t just store those keys as-is. So I added encryption using AES256 via GPG. That way, even if someone somehow gets access to the backup, the sensitive data stays protected. Of course, this adds a bit of friction — to restore those files, I need to use a passphrase stored in a separate file — but that’s a trade-off I’m fine with.
I also integrated the script with cron, so it runs automatically at scheduled times. That was an important step. I didn’t want backups to depend on me remembering to run them. Now it just happens in the background, which reduces the risk of human error and makes the whole system feel much more reliable.
I developed a simple backup system that will load my backups to Dropbox in bash
Yesterday I had some problems with my laptop, more precisely with my browser Firefox. Luckily today everything was calm, and I didn't have any accidents with it. But I need to continue this topic and share some important moments, how I recovered my tabs, and about my own backup system. Because I was really lucky that I had the opportunity to recover my tabs, and my own simple backup system also brought me unique experiences. Honestly, it was very interesting to try a new programming language to develop something useful, not just to try it one time and then forget it.
I recovered my tabs and some parts of my history, and I was not sure how it was possible. But about history, something was understandable even though I had some doubts. Because I had synchronization with my Firefox account and some of my data was loaded there, as a result, after login, it automatically pulled back. About tabs, I was really lucky because the extension Simple Tab Groups, which I use to group the tabs, automatically made backups of my tabs. Of course it's helped me recover all my tabs that I saved in the last four years.
Therefore, after that crash, I didn't want to lose anything, and I tried to develop my backup system. This is my first bash script in my life. Before I just heard about it, but I never tried doing something. I developed it especially to make backups for Firefox configs. But after, I realized that I can back up all my important things automatically via this script and without third-party solutions. I think it wasn't bad for my own personal use, but right now I can't decide effectively or no. Fortunately I like it and I'm ready to improve my code.
This script is simple, and right now I configured backing up for Firefox configs, my private documents, SSH configs, and operating system configs. The work principles are also simple: it just takes files and folders from special places in the section (Sources), copying them by archiving them to my local Dropbox folder. After that, everything automatically synchronizes with Dropbox servers in real time, and Telegram is notified about a successful backup.
However, I need to remark about a few features that I realized. While I was racking my brain about backing up my .ssh configs, I added protection logic with the encryption method AES256. Because that folder keeps private keys that I use to connect to other servers. So it was necessary for me, and if I need to use protected files, of course I can't use them easily; instead, I need to provide my special password from this file, .backup_gpg_pass.
Also, my script works with the cron planning manager. I set my specific time, and the script runs a backup only during that time automatically. It should give me extra flexibility, and I don't check and make my backups manually. It also reduces the risk of forgetting about running a backup and just not thinking about it.