Skip to content

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

gtakeout-auto

Keeping a backup of your Google Account is essential, as losing access to it could be disastrous.

Google provides Google Takeout, a tool that allows you to generate a complete copy of your data. However, manually going through the process of creating an archive, downloading it, and storing it on a hard drive can be tedious—so I automated it!

How It Works

  1. Google Takeout Automation: Google Takeout is configured to automatically export data to Google Drive every two months.
  2. Local Backup: A Raspberry Pi with an external hard drive runs a Python script that periodically checks for new Takeout exports in Google Drive.
  3. Download & Cleanup: If a new export is found, the script downloads it to the local hard drive, removes the old backup, and cleans up the Takeout folder in Google Drive.

Prerequisites

Ensure the following dependencies are installed on your system:

  • Python 3 (python3)
  • pip for Python 3 (python3-pip)
  • rclone (for interacting with Google Drive)

Install Python 3 and pip

If Python 3 and pip are not already installed, run the following command:

sudo apt update && sudo apt install -y python3 python3-pip

Installation

1. Install and Configure rclone

a) Install rclone

Follow the official rclone installation guide to install it on your system.

b) Configure Google Drive as an rclone remote

Refer to the rclone documentation to set up Google Drive as a remote.
It is recommended to name the remote default.


2. Mount the External Hard Drive

Since the backup files are large, it's best to use an external hard drive. Follow these steps to properly mount it.

a) Identify the Drive's UUID

Run the following command to find the drive’s UUID:

sudo blkid

Look for your drive (e.g., /dev/sda), which will have an output similar to:

/dev/sda: UUID="YOUR_UUID_HERE" TYPE="ntfs"

Copy the UUID value (inside the quotes).

b) Create a Mount Point

sudo mkdir /mnt/usb

c) Automate Mounting via fstab

Edit the /etc/fstab file:

sudo nano /etc/fstab

Add this line at the end (replace YOUR_UUID_HERE with the copied UUID):

UUID=YOUR_UUID_HERE /mnt/usb ntfs-3g defaults,auto,users,permissions 0 0

Save and exit (CTRL + X, then Y, then Enter).

d) Test the Mount

Manually mount all drives to check if the configuration is correct:

sudo mount -a

Verify by listing the contents of the mounted drive:

ls /mnt/usb

e) Reboot and Verify

Restart the Raspberry Pi:

sudo reboot

After rebooting, ensure the drive is still mounted:

ls /mnt/usb

If the files are visible, the setup is complete.


3. Set Up the Backup Script

  1. Clone the repository:
git clone https://gitlab.com/niehaus1301/gtakeout-local.git
  1. Navigate to the directory:
cd gtakeout-local
  1. Create a virtual environment at the project root (/venv):
python3 -m venv venv
  1. Activate the virtual environment:
source venv/bin/activate
  1. Install required dependencies:
pip install -r requirements.txt
  1. Run the script manually:
python3 main.py <rclone remote name (default)> <path to local backup directory>

Example:

python3 main.py default /mnt/usb

4. (Optional) Run as a Background Service

If you want the script to run automatically in the background, you can set it up as a systemd service.

a) Copy the Service File

At the root level of the repository, there is a gtakeout-auto.service file. Copy it to the appropriate systemd directory:

sudo cp gtakeout-auto.service /etc/systemd/system/

b) Enable and Start the Service

Reload systemd to recognize the new service:

sudo systemctl daemon-reload

Enable the service to start automatically on boot:

sudo systemctl enable gtakeout-auto.service

Start the service manually for the first time:

sudo systemctl start gtakeout-auto.service

c) Check Service Status

To confirm that the service is running, use:

sudo systemctl status gtakeout-auto.service

If everything is working correctly, you should see output indicating that the service is active and running.


5. Configure Google Takeout

  1. Go to Google Takeout.
  2. Select all the data you want to back up.
  3. Under "Choose file type, frequency and destination", select "Add to Drive".
  4. Set the frequency to "Export every 2 months for 1 year".
  5. Adjust "File type & size" as needed.
  6. Click "Create export"—you're done!

Example Configuration Screenshot

screenshot


Now, your backups will be automatically downloaded and stored securely! 🚀