rclone (with OneDrive personal) with rpi and the pi camera (python 3)
rclone setup on headless device
1. Installation
<command>sudo apt-get install rclone</command>
2. Setup [bash] – On RPI machine
<command>rclone config</command>authorise headless
– rclone headless
<command>rclone authorize “onedrive”</command> [on a machine that has a browser]
– copy the code to console and paste
– choose onedrive (personal)
Finished.
3. Configuration [python]
– rcloneCommand = ‘/usr/bin/rclone -v copy /home/pi/python-scripts/pi-cam/timelapse/ onedrive:Documents/Personal/RPI-Projects/backups/rpizerow-10-88-10-15-media-room/
– outputRcloneResult = subprocess.getoutput(rcloneCommand)
– print(outputRcloneResult,”Rclone Command run :”,rcloneCommand)
– print(counter,”,”,”Rclone Command run :”,rcloneCommand,”,”,now.strftime(“%Y-%m-%d %H:%M:%S.%f”),file=open(PATH+”pi-cam-“+now.strftime(“%Y-%m-%d”)+”.pi-cam.log”, “a”))
Example Backup script :
<?php
//Version 20180602 1.4
//added sudo to command
//make sure correct timezone is used
date_default_timezone_set(‘Australia/Brisbane’);
$path = “/home/pi/backups”; // full server path to the directory where you want the backup files (no trailing slash)
#$result = “”;
#$result1 = “”;
if (is_dir($path) == FALSE)
{
mkdir($path, 0755);
}
#Debug
#print(“<p>” . date(“Y_F_d_H_i_s”) . “</p>”);
// modify the above values to fit your environment
$target = $path . “/backup_rpizerow-10-88-10-15_media_files” . date(“_Y_F_d_H_i”) . “.tar.gz”;
if (file_exists($target)) unlink($target);
system(“sudo /bin/tar –create –preserve-permissions –gzip –file=”.$target.” /home/pi/.rclone.conf /home/pi/.bash_history /home/pi/bash-scripts /home/pi/html-php-scripts /home/pi/python-scripts /etc 2>&1″,$result);
#print(“<p>Result: $result</p>”);
#Debug
#print(“<p>” . date(“Y_F_d_H_i_s”) . “</p>”);
#$size = filesize($target);
#switch ($size)
#{
# case ($size>=1048576): $size = round($size/1048576) . ” MB”; break;
# case ($size>=1024); $size = round($size/1024) . ” KB”; break;
# default: $size = $size . ” bytes”; break;
#}
#rclone backup to Onedrive
$onedrivePath = ‘onedrive:Documents/Personal/RPI-Projects/backups/rpizerow-10-88-10-15-media-room/’;
$rcloneCommand = ‘/usr/bin/rclone -v copy ‘ . $target . ” ” . $onedrivePath . ‘ 2>&1’;
print(“<p>rcloneCommand: $rcloneCommand</p>”);
system($rcloneCommand,$result1);
#print(“<p>Result1: $result1</p>”);
#Debug
#print(“<p>” . date(“Y_F_d_H_i_s”) . “</p>”);
?>