This repository was archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.js
More file actions
55 lines (51 loc) · 2.35 KB
/
upload.js
File metadata and controls
55 lines (51 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { exec } = require("child_process");
const querystring = require('querystring');
const https = require("https");
require('dotenv').config();
var awsbucket = process.env.AWSBUCKETNAME
var awsaccesskeyid = process.env.AWSACCESSKEYID
var awssecretaccesskey = process.env.AWSSECRETACCESSKEY
var upload = 'sudo docker exec otnode node scripts/backup-upload-aws.js --config=/ot-node/.origintrail_noderc --configDir=/ot-node/data --backupDirectory=/ot-node/backup --AWSAccessKeyId='+awsaccesskeyid +' --AWSSecretAccessKey='+awssecretaccesskey+' --AWSBucketName=' + awsbucket
function PushNotification(PushTitle, PushText)
{
var apiKey = process.env.APIKEY
var postdata = querystring.stringify({
'ApiKey': apiKey,
'PushTitle': PushTitle,
'PushText': PushText,
});
var options = {
hostname: 'www.notifymydevice.com',
port: 443,
path: '/push?',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postdata.length
}
};
callback = function (response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log('Response: ' + str);
});
}
var req = https.request(options, callback);
req.write(postdata);
req.end();
req.on('error', function (e) {
Log(e);
});
}
exec(upload, (error, upload, stderr) => {
if (error){
PushNotification(process.env.NODENAME + " failed to trigger backup script.",error);
}else{
PushNotification(process.env.NODENAME + " backup script triggered.",'If your .env configuration was correct, you can check AWS S3 to find your backup.');
}
});