CentOS 6 定时自动备份数据到 Google Drive
发布于 分类 Linux
更新于 2016-08-30
50天前 有1个用户阅读过
我一直使用的定时自动备份VPS数据的解决方案是,小的压缩包,比如数据库自动发送到邮箱,大一点的数据,比如网站整站数据在VPS定时备份,由于没有适合的FTP空间或者云盘放,所以没同步到其他地方,但是服务器硬盘始终有挂掉的风险。
Google Drive不交钱的话只有15G,自动备份空间可能很快就用完,所以脚本定时备份的话,需要和本地一样,定时删除老的压缩包,只保留几份新的压缩包。
用Google Drive测试了一下这个博客的VPS,速度挺快的。
定时备份脚本网络上比较多,重点是是如何在linux服务器上使用Google Drive。
下载和设置 Google Drive
到 github 上去下载对应的版本 https://github.com/prasmussen/gdrive#downloads, 找到VPS对应的linux版本下载链接后,执行
wget -O /usr/sbin/gdrive https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA
把 Google Drive 的 CLI 命令行工具下载到 /usr/sbin/ 目录下,并命名为 gdrive,执行
chmod 755 /usr/sbin/gdrive
给 gdrive 添加可执行属性。最后执行
gdrive about
会输出一个链接并等待用户输入 token,浏览器打开该链接即可得到一个 token,将 token 输入到终端即可,当然前提是得先有一个 Google 账号。
这时 gdrive 会在 home 目录下创建一个 .gdrive 文件夹,能访问该文件夹的用户也能访问你的 Drive。
怎么使用gdrive
这里有个demo:
# gdrive 上传 tar 包到目录 0B2_oloQ2sUujdzFiYkNtOGhNMkU(用gdrive list查询google drive对应的目录地址),成功后删除 tar 包
/usr/sbin/gdrive upload -p 0B2_oloQ2sUujdzFiYkNtOGhNMkU --delete"/tmp/seonoco.com.tar.gz"
可使用gdrive help 与对应的命令 比如gdrive help upload查询详细的用法
[root@localhost backup]# gdrive help
gdrive usage:
gdrive [global] list [options] List files
gdrive [global] download [options]Download file or directory
gdrive [global] download query [options]Download all files and directories matching query
gdrive [global] upload [options]Upload file or directory
gdrive [global] upload - [options]Upload file from stdin
gdrive [global] update [options]Update file, this creates a new revision of the file
gdrive [global] info [options]Show file info
gdrive [global] mkdir [options]Create directory
gdrive [global] share [options]Share file or directory
gdrive [global] share listList files permissions
gdrive [global] share revokeRevoke permission
gdrive [global] delete [options]Delete file or directory
gdrive [global] sync list [options] List all syncable directories on drive
gdrive [global] sync content [options]List content of syncable directory
gdrive [global] sync download [options]Sync drive directory to local directory
gdrive [global] sync upload [options]Sync local directory to drive
gdrive [global] changes [options] List file changes
gdrive [global] revision list [options]List file revisions
gdrive [global] revision download [options]Download revision
gdrive [global] revision deleteDelete file revision
gdrive [global] import [options]Upload and convert file to a google document, see 'about import' for available conversions
gdrive [global] export [options]Export a google document
gdrive [global] about [options] Google drive metadata, quota usage
gdrive [global] about import Show supported import formats
gdrive [global] about export Show supported export formats
gdrive version Print application version
gdrive help Print help
gdrive helpPrint command help
gdrive helpPrint subcommand help
[root@localhost backup]# gdrive help upload
Upload file or directory
gdrive [global] upload [options]global:
-c, --configApplication path, default: /root/.gdrive
--refresh-tokenOauth refresh token used to get access token (for advanced users)
--access-tokenOauth access token, only recommended for short-lived requests because of short lifetime (for advanced users)
options:
-r, --recursive Upload directory recursively
-p, --parentParent id, used to upload file to a specific directory, can be specified multiple times to give many parents
--nameFilename
--no-progress Hide progress
--mimeForce mime type
--share Share file
--delete Delete local file when upload is successful
--timeoutSet timeout in seconds, use 0 for no timeout. Timeout is reached when no data is transferred in set amount of seconds, default: 300
--chunksizeSet chunk size in bytes, default: 8388608
-- The End --