Marcio Cunha

How to automate Chrome profile backup on Linux with Bash

Learn how to build a simple and efficient Bash script to backup your Google Chrome profile on Linux, ensuring your extensions and data remain secure offline.

Marcio Cunha•2 min
Also available in:PortuguêsEspañol
Summary
  • The Chrome profile directory contains all browser history, extensions, and sensitive user settings.
  • Bash scripts allow for efficient automation of repetitive tasks like backing up specific folders with timestamps.
  • Excluding temporary folders such as Cache and GPUCache drastically reduces backup size without losing critical data.
  • Using the rsync command ensures efficiency by only copying files that have changed since the last run.
  • Storing backups locally on a separate drive protects against cloud synchronization failures and account issues.

Why back up your Chrome profile manually?

Google Chrome saves almost everything you do in a local folder called 'Default' or 'Profile'. This encompasses your browsing history, saved passwords, installed extensions, session cookies, and interface settings. Relying solely on cloud synchronization means that an account issue or accidental deletion could lead to permanent data loss. Automating a copy to a safe location on your hardware is a core practice for digital resilience.

Understanding the profile directory structure on Linux

On Linux systems, the Chrome profile is typically located at ~/.config/google-chrome/. Inside this folder, you will find multiple subdirectories. The most important one is the one holding your actual user data. When automating, we must be careful to ignore temporary file directories such as 'Cache', 'GPUCache', and 'Code Cache'. These folders contain nothing you need to restore and, if included, would make your backups balloon to several gigabytes needlessly.

Building an efficient backup script with Bash

For this task, we will use the rsync command, a robust Linux tool designed for file synchronization. rsync is far superior to the cp command because it identifies which files have changed and copies only the differential, saving time and resources. Besides using the terminal for hardware automation tasks, maintaining a backup structure with dates allows for a simple version history.

#!/bin/bash
# Initial settings
SOURCE=~/.config/google-chrome/
DEST=/path/to/your/backup/chrome_backup_$(date +%F)

# Run backup excluding temporary folders
rsync -av --delete --exclude='Cache*' --exclude='Code Cache' $SOURCE $DEST

echo 'Backup completed successfully at: '$DEST

How to automate periodic execution

Having the script is the first step, but it is only useful if it runs regularly. For this, we use cron, the system's task scheduler. Simply open your terminal and type crontab -e. There, you can add a line telling the system to run your script every day at midnight, for example. This ensures that even if you forget to backup, your computer handles it silently, much like how we filter journald logs with jq to maintain system health. To explore these architectural concepts further in production, see our related technical analysis on How to test PC fan PWM signal with a multimeter.

Conclusion

Retaining full control over your data is what separates a power user from a casual one. By decoupling your browser's security from total reliance on external servers, you gain peace of mind. Ensure you test your script at least once, verifying that important files, such as the 'Local Storage' folder, are present in the target directory.