2023-08-08
Backups Setup
How my current setup works
I use syncthing on mobile to backup my TachiyomiSy automatic backups, and images currently to my laptop. I wrote a small bash script which uses rclone to upload the following folders on my laptop to google drive.
- Documents (this is where my obsidian notes, mobile backups through syncthing land)
- Downloads
- Pictures
- Videos
- College dir
I then use systemd timers to run this script on boot weekly.(Alternatively you can use chron
to setup a chron job).
Setting up Syncthing
This was pretty straight forward. I downloaded on both my android device and laptop(I used to yay
to get it and I think it also comes with a systemd unit which you can enable to start it on boot). I added my laptop as a remote device then the folders I wanted to sync uni-directionally except for obsidian which is two-way. On laptop I use my Documents/<folder name>
as destination. Later I configured syncthing on android to sync when connected to wifi.
I got to the idea of using syncthing from this video.
Setting up rclone
I used to use rclone for other things earlier so I just defaulted to using this for my script.
- Setup rclone remote.(https://rclone.org/drive/)
- In terminal type
rclone config
. - Choose
new remote
. - Enter a name of your choice.
- When prompted for storage, enter
drive
or you can alternatively enter the number. - Leave blank(as in choose the defaults) pretty much everything except for scopes where you add what you think suits your needs. My case I chose
1
giving full access.
- In terminal type
- Test the new remote by running
rclone lsf <remote name>:
.
The bash script
#!/usr/bin/bash
#backup.sh
sources=("$HOME/Pictures" "$HOME/Documents" "$HOME/Videos" "$HOME/wallpapers" "$HOME/Downloads" "$HOME/College")
remote="remote_name:backups/linux"
backup_dir="remote_name:backups/previous/linux"
for dir in "${sources[@]}"; do
dir_name=$(basename "$dir")
echo "Backing up to $remote/$dir_name"
rclone sync "$dir" "$remote/$dir_name" --backup-dir "$backup_dir/$dir_name" -P -c --transfers 15
echo ""
done
echo "Backups completed"
The systemd unit
[Unit]
Description=Gdrive backup service
[Service]
Type=oneshot
ExecStart=%h/.local/bin/scripts/backup.sh
[Install]
WantedBy=gdrive-backup.timer
The systemd timer
[Unit]
Description=Timer running weekly to take backups
[Timer]
OnCalendar=weekly
; Uncomment this if you want some delay
; RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.target
Update: For android I am using syncthing fork over the official app mainly because in the fork I can set custom sync conditions for each folder. So I set obsidian folder to sync even over mobile data whereas the remaining folders only sync over wifi.