Auto compression folder and backup to Google Drive

By gdive cli program.

1. Install 7z

Then you should test whether 7z working.

1
2
sudo apt install p7zip-full
7z l

2. Auth gdrive

1
2
3
4
wget -O gdrive "https://drive.google.com/uc?id=1Ej8VgsW5RgK66Btb9p74tSdHMH3p4UNb&export=download"
chmod +x gdrive
sudo mv gdrive /usr/bin/
gdrive about

3. Edit backup script

1
2
3
4
5
6
7
8
#!/bin/bash
curDate=$(date +%Y%m%d%H%M%S)
path_name='/path_name'
folder_name='folder_name'
folder_id='folder_id'
7z a "$path_name"/"$curDate".7z "$path_name"/"$folder_name"
gdrive upload "$path_name"/"$curDate".7z -p "$folder_id"
rm "$path_name"/"$curDate".7z

folder_id in your google drive url, like this:
drive.google.com/drive/folders/folder_id

4. Cron task

1
2
sudo apt install crontab
crontab -e

Type :wq

1
2
crontab -l
crontab -e

Type * * * * * /bin/bash /"$path_name"/"$folder_name"
You should custom your path.
Then type :x save and exit.
Now you can wait 1 minute to check whether crontab working.
You can also custom backup time.
Crontab usage: https://www.geeksforgeeks.org/crontab-in-linux-with-examples/

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×