./movie.backup.sh 没有权限
来源:9-6 上传数据库备份到七牛私有云
人间能得几回闻
2017-10-03
hujian@ubuntu-jhf:~/tasks$ ./movie.backup.sh -bash: ./movie.backup.sh: Permission denied hujian@ubuntu-jhf:~/tasks$ sudo ./movie.backup.sh sudo: ./movie.backup.sh: command not found hujian@ubuntu-jhf:~/tasks$ sudo sh ./movie.backup.sh 2017-10-03T18:44:59.566+0800 writing imooc-movie.users to 2017-10-03T18:44:59.567+0800 done dumping imooc-movie.users (1 document) movie_2017_10_03_1844/ movie_2017_10_03_1844/imooc-movie/ movie_2017_10_03_1844/imooc-movie/users.bson movie_2017_10_03_1844/imooc-movie/users.metadata.json ./movie.backup.sh: 16: ./movie.backup.sh: node: not found PS: 找了下第16行: NODE_ENV=$backUpFolder@$backFileName node /home/hujian/tasks/upload.js 对比了下第16行应该没错,upload.js路径也没问题,提示 node not found hujian@ubuntu-jhf:~/tasks$ sh movie.backup.sh 2017-10-03T18:49:08.892+0800 writing imooc-movie.users to 2017-10-03T18:49:08.893+0800 done dumping imooc-movie.users (1 document) movie_2017_10_03_1849/ movie_2017_10_03_1849/imooc-movie/ movie_2017_10_03_1849/imooc-movie/users.bson movie_2017_10_03_1849/imooc-movie/users.metadata.json I am the Path: /home/hujian/backup/movie/movie_2017_10_03_1849.tar.gz /home/hujian/tasks/node_modules/qiniu/qiniu/storage/rs.js:659 throw new Error('invalid putpolicy options'); ^ Error: invalid putpolicy options at new PutPolicy (/home/hujian/tasks/node_modules/qiniu/qiniu/storage/rs.js:659:11) at uptoken (/home/hujian/tasks/upload.js:18:19) at Object.<anonymous> (/home/hujian/tasks/upload.js:22:9) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:389:7) PS: 看了下 App Key and Secret KEY 也是正确的,filepath等参数也没错 报putpolicy错 // ******请问老师 怎么解决呢? // *******以下为movie.backup.sh #!/bin/sh backUpFolder=/home/hujian/backup/movie date_now=`date +%Y_%m_%d_%H%M` backFileName=movie_$date_now cd $backUpFolder mkdir -p $backFileName mongodump -h 127.0.0.1:19999 -d imooc-movie -u imooc_movie_runner -p 940716* -o $backFileName tar zcvf $backFileName.tar.gz $backFileName rm -rf $backFileName NODE_ENV=$backUpFolder@$backFileName node /home/hujian/tasks/upload.js // ******一下为upload.js var qiniu = require("qiniu"); var parts = process.env.NODE_ENV.split('@') var file = parts[1] + '.tar.gz' var filePath = parts[0] + '/' + file console.log('I am the Path: ' + filePath) //需要填写你的 Access Key 和 Secret Key qiniu.conf.ACCESS_KEY = 'oH7lCa_KzUHYlmMqSk1hv8sjwex0uXujYISCQq80'; qiniu.conf.SECRET_KEY = 'oACBQBUixYI58Mmof1sDFHolDNag3fq3BPUgejJC'; //要上传的空间 bucket = 'imoocdeploydb'; //上传到七牛后保存的文件名 key = file; //构建上传策略函数 function uptoken(bucket, key) { var putPolicy = new qiniu.rs.PutPolicy(bucket+":"+key); return putPolicy.token(); } //生成上传 Token token = uptoken(bucket, key); //要上传文件的本地路径 //filePath = './ruby-logo.png' //构造上传函数 function uploadFile(uptoken, key, localFile) { var extra = new qiniu.io.PutExtra(); qiniu.io.putFile(uptoken, key, localFile, extra, function(err, ret) { if(!err) { // 上传成功, 处理返回值 console.log('上传成功:'); console.log(ret.hash, ret.key, ret.persistentId); } else { // 上传失败, 处理返回代码 console.log('上传失败:'); console.log(err); } }); } //调用uploadFile上传 uploadFile(token, key, filePath);
写回答
2回答
-
apalcino
2017-11-01
我也遇到了同样的问题,我是这么解决的。
'node not found'
去掉了sudo, sh ./movie.backup.sh;
第二个问题是 qiniu 的版本问题,
卸载了当前安装的 7.0 之后的版本,yarn add qiniu@6.1.11 ,问题便解决了。
10 -
Scott
2017-10-08
这是两个问题,第一个是 node 的执行权限
先试试把 sh 里的 node 路径修改下
NODE_ENV=$backUpFolder@$backFileName node /home/hujian/tasks/upload.js
把 node 换成绝对路径
然后就是七牛的上传方法,应该是官方的 SDK 和使用姿势都有升级,按照这个文档改一下试试:
https://developer.qiniu.com/kodo/sdk/1289/nodejs#server-upload
00
相似问题