在写东西以前。首先先感谢下这款好工具脚本的做者:[weblink url="https://github.com/oott123"]@oott123[/weblink]; 好了,进入今天主题。前段时间各大互联网公司都在轰炸网盘这块蛋糕。送100G不够,送1T,送1T不够就送10T...最后发展到某些 厂家已经进入无限网盘的境地。这么大的存储量。相信不是照片,小电影或者其余东西能装得完的。做为站长。咱们能够充分利用这免费的空间打造一个免费的vps备份利器。
介绍今天的主角——bpcs_uploader
bpcs_uploader利用百度开放的API接口。对百度网盘应用数据进行操做,能够实现,查询容量(配额)、上传文件、下载文件、删除文件、离线下载; [h2]系统要求:[/h2]Linux (or cygwin) with php & curl installed. linux须要安装php环境,而且安装curl才能使用本脚本。 查看方式:rpm -qa |grep -E "php|curl" php也能够直接使用php -v看到版本就说明有php环境; 有了环境,咱们就能够进入下一步了; [h2]下载bpcs_uploader[/h2]
wget https://github.com/oott123/bpcs_uploader/zipball/master; unzip master; #以后会生成一个oott123开头的目录能够修更名字为bocsuploader
[h2]初始化脚本 ps:这块做者说的很详细了。Readme摘抄之[/h2]
#进入这个目录: cd bocsuploader; #给bpcs_uploader.php附上可执行权限: chmod +x bpcs_uploader.php 执行 ./bpcs_uploader.php 因为VPS上安装的php可能存在于各类地方,所以运行极可能不正常。请以使用`which php`获得你的php绝对路径,修改bpcs_uploader.php的头一句#!后的路径。 若是你的php是为了网站环境安装的,那么颇有可能你会获得下面这条错误消息: > xxx() has been disabled for security reasons 那么说明你的环境因为安全缘由禁止了部分函数的执行。请看FAQs的1。请使用那条长长的命令代替./bpcs_uploader.php。eg:`php -d disable_functions -d safe_mode=Off -f bpcs_uploader.php quota` ### 快速初始化 ./bpcs_uploader.php quickinit 敲下命令直接进入快速初始化流程,输入y,而后打开浏览器访问 https://openapi.baidu.com/device ,在“请输入设备上显示的用户受权码:”文本框中输入上面显示的受权码(这里是`12abcxyz`),并点击继续。 看到网页上显示“请返回设备继续操做!”后,返回ssh上按下回车后,即完成了初始化配置。 ### 初始化 ./bpcs_uploader.php init 敲下命令以后会进入初始化流程,这里分段详述设置方法。 > Uploader initialization will be begin. If you have already configured the uploader before, your old settings will be overwritten. > Continue? [y/N] y 确认初始化。若是以前有初始化过,那么之前的配置将会被覆盖。 > Please enter your PSC App API Key. You can get this key by visiting http://developer.baidu.com/dev#/create > If you have already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app's info. > If you don't want to bother creating an app, you can press Enter to use the demo API Key. > Doing so (without your own API Key/Secret) will cause the access-token to expire every 30 days, and you'll have to re-initialize when it expires. > App API KEY [uFBSHEwWE6DD94SQx9z77vgG] : 第一步,输入App key。这里须要输入一个有PCS权限的API KEY,若是没有的话直接敲回车就行了,这里会默认使用内置的一组app key,app secret和app folder name,因此只要敲下回车就能直接跳到第四步。若是你没有App secret(例如使用L6g70tBRRIXLsY0Z3HwKqlRE这个Key时),只能获取一个有效期为一个月的access token。若是有一个有PSC权限的API KEY和secret,那么就能得到一个有效期为10年的refresh token,以便长期使用。 > App API Key has been set to uFBSHEwWE6DD94SQx9z77vgG . > Please enter your Baidu PSC App API Secret. If you have no idea what it is, keep it blank. > App API SECRET [] : 第二步,输入App secret。若是输入了app secret,将会转到device code模式验证;或者直接输入回车使用oob模式验证。先直接回车: > Please enter your app's folder name. You can choose to input this later in the file [ /root/_bpcs_files_/config/appname ]. > ** Why do I have to enter the app's folder name? Please check the FAQs. ** > If your app's name has Chinese characters, please ensure that your client supports UTF-8 encoding. > Below are some Chinese characters for testing. Please make sure that you can read them before you enter Chinese here. > 这里是一些中文字符。 > If you can't read the characters above, please press Enter and change it manually within the file [ /root/_bpcs_files_/config/appname ]. > If you have Enter the key [L6g70tBRRIXLsY0Z3HwKqlRE] (by default) , just press Enter. > App Name [pcstest_oauth] : 第三步,这里须要输入app folder name,也就是你申请API时填写的文件夹名字。详情见FAQ 2。由于是使用的默认的key,因此直接回车便可。 > In the next step, you'll have to grab the access_token generated by Baidu. > You can check out this link for more information on this procedure: > http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/usage_example > > Easy Guide: > 1. Visit https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=$appkey&redirect_uri=oob&scope=netdisk > 2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor. > 3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes). > 4. Copy it and paste here, then press Enter. > access_token[] : 第四步,获取access token。在浏览器中打开上述URL( https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=L6g70tBRRIXLsY0Z3HwKqlRE&redirect_uri=oob&scope=netdisk ),进行受权。 受权完毕后,将会跳到一个写着“百度 Oauth2.0”的页面。复制出其中的网页URL,找到access_token=和&之间的字符串,例如: `3.**05c2ea85d52c2***************a5.2592000.136***9032.3089166538-23**47` 将其复制到shell中粘贴并回车。使用这种方式初始化的用户,须要每个月从新初始化。 若是第三步输入app secret的时候没有留空,将会获得下面的消息: > Launch your favorite web browser and visit https://openapi.baidu.com/device > Input 12abcxyz as the user code if asked. > After granting access to the application, come back here and press Enter to continue. 来到这里,打开浏览器访问 https://openapi.baidu.com/device ,在“请输入设备上显示的用户受权码:”文本框中输入上面显示的受权码(这里是`12abcxyz`),并点击继续。 看到网页上显示“请返回设备继续操做!”后,返回ssh上按下回车后,便可继续。 > curl -X GET -k -L "...." > % Total % Received % Xferd Average Speed Time Time Time Current > Dload Upload Total Spent Left Speed > 0 62 0 62 0 0 40 0 --:--:-- 0:00:01 --:--:-- 235 > Access Granted. Your Storage Status: 0.06G/115.00G (0.05%) > Enjoy! 你所看到的输出可能和这里给出的不同,可是只要看到了存储空间的剩余量,和【Have fun !】提示,即说明成功初始化。
使用
### 上传文件 ./bpcs_uploader.php upload [path_local] [path_remote] 路径格式:`foo/bar/file.ext`(路径中必定要包括文件名) 上传后,能在百度网盘/个人应用数据/应用名/foo/bar下找到一个叫file.ext的文件。 完整事例 ./bpcs_uploader.php upload /home/wwwroot/xxx.tag.gz xxx.tag.gz ### 下载文件 ./bpcs_uploader.php download [path_local] [path_remote] 完整事例 ./bpcs_uploader.php download /home/wwwroot/xxx.tag.gz xxx.tag.gz ### 删除文件 ./bpcs_uploader.php delete [path_remote] 完整事例 ./bpcs_uploader.php delete xxx.tag.gz ### 离线下载 ./bpcs_uploader.php fetch [path_remote] [path_to_fetch] 这个就是利用百度网盘离线下载功能。咱们备份网站貌似用不到
[warning]1. 各类错误提示 试试`php -d disable_functions -d safe_mode=Off -f bpcs_uploader.php`。 2. 为何要输入文件夹名? 由于百度PCS的权限被限制在了/apps/文件夹名/下。若是发现输入文件夹名后仍然没法上传文件,请经过网页版找到【个人应用数据】找到对应的文件夹名,写入/config/appname文件。上传文件的时候会自动帮您处理文件夹,无需手动写出完整路径。[/warning]
shell自动备份网站数据到百度网盘