Ubuntu18.04LTS

Ubuntu18.04.2LTS使用Gdrive同步文件、自动备

2019-04-02  本文已影响9人  97690CE50CC872D

Ubuntu18.04.2LTS使用Gdrive同步文件、自动备份Hexo源文件

Gdrive项目地址

Gdrive是一个命令行操作Google云端硬盘账户的操作工具

准备工作

注意事项

安装Gdrive

该工具的官方GitHub页面 ,并下载系统的可执行文件

$ wget -O ~/gdrive  "https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA&export=download"   ##gdrive-linux-x64

$ chmod +x ~/gdrive    ##添加可执行权限

$ sudo ln -s  ~/gdrive/gdrive   /usr/bin/gdrive     ##建立软连接

授权Gdrive

为确保该工具能连接到Google云端硬盘账户,需要执行gdrive about进行授权,之后会在用户目录下生成.gdrive文件夹产生配置文件,不需要记得删除文件夹

$ gdrive about
gdrive about
把这串网址粘贴到浏览器并登入账号
image
点击允许会返回一串代码,复制
image
回到终端,将复制的代码粘贴上去
image

使用Gdrive

常用命令如下,更多查看gdrive官网:gdrive

$ gdrive list
$ gdrive download {文件(夹)名}
$ gdrive upload {文件(夹)名}

本地文件上传到指定目录

$ gdrive upload --parent {Dir id} {文件(夹)名}
$ gdrive mkdir {文件夹名}

:Dir id可以通过gdrive list查看

image

附上自动备份Hexo源文件脚本

按需要修改自己所要备份的文件

#!/bin/sh
##---------------Folder you want to backup----------------##
NameOfFolder="hexo"
SourceOffFolder="/home/xmaihh/Documents"
BackupLocation="/home/xmaihh/backups"
date=$(date +"%Y-%m-%d")
LOG_FILE="home/xmaihh/googledrive.log"
##-----That mean,you will Backup the folder /home/xmaihh/Documents/hexo and will save into Folder /home/xmaihh/backups

if [ ! -d $BackupLocation ]; then
mkdir -p $BackupLocation
fi
find $BackupLocation/*.zip -mtime +10 -exec rm {} \;
for fd in $NameOfFolder; do
# Name of the Backup File
file=$fd-$date.zip

# Zip the Folder you will want to Backup
echo "Starting to zip the folder and files"
cd $SourceOffFolder
zip -r $BackupLocation/$file $fd
sleep 5s
## Process Upload Files to Google Drive
gdrive upload $BackupLocation/$file
if test $? = 0
then
echo "Your Data Successfully Uploaded to the Google Drive!"
else
echo "Error in Your Data Upload to Google Drive" > $LOG_FILE
fi
done

Reference

Gdrive:Linux下同步Google Drive文件、自动备份网站到Google Drive

上一篇下一篇

猜你喜欢

热点阅读