Actions

Rclone Pictures to Google Drive

From Rabbi Blog

Revision as of 21:40, 15 September 2020 by Rabbi Bob (talk | contribs) (Created page with " =Move Files ===Perl=== * Purpose: ** Read source dir ** Rename files and move to a Year\Month\Day structure <pre> use strict; use warnings; use English; use File::Basename...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

=Move Files

Perl

  • Purpose:
    • Read source dir
    • Rename files and move to a Year\Month\Day structure
use strict;
use warnings;
use English;
use File::Basename qw( fileparse );
use File::Path qw( make_path );
use File::Spec;
use File::Copy;

my $dir = '/home/somedir/checkmail';
my $destination ='/home/somedir/securitycameras/'; #softlink
foreach my $fp (glob("$dir/*.jpg")) {
#  printf "%s\n", $fp;

print "_______________________________________\n";
print "Source File: $fp\n";

my $filename_year="";
my $filename_month="";
my $filename_day="";
my $filename_camera="";
my $filename_time="";
my $filename_extension="";
my $output_filename="";
#04_20190430185212.jpg

if ( $fp =~ /(\d\d)_(\d{4})(\d{2})(\d{2})(.*)(.jpg)/ ) {
#print "$1\n";
$filename_year=$2;
$filename_month=$3;
$filename_day=$4;
$filename_camera=$1;
$filename_time=$5;
$filename_extension=$6;
$output_filename=$filename_year.$filename_month.$filename_day.'_'.$filename_time.'_'.$filename_camera.$filename_extension;
print "Output File: $output_filename\n";
}
### Check for destination directory - YEAR
my $dest_year = $destination.$filename_year;
print "Dest Year: $dest_year\n";

### Check for destination directory - MONTH
my $dest_month = $dest_year.'/'.$filename_month;
print "Dest Month: $dest_month\n"; 

### Check for destination directory - DAY
my $dest_day = $dest_month.'/'.$filename_day;
print "Dest Day: $dest_day\n";

### Dest File

my $dest_file = $dest_day.'/'.$output_filename;
print "Dest File: $dest_file\n";

############# Create Dirs ################

	if ( !-d $dest_year ) 
		{
		print "Creating $dest_year\n";
    		make_path $dest_year or die "Failed to create path: $dest_year";
		}
	if ( !-d $dest_month ) 
		{
		print "Creating $dest_month\n";	
    		make_path $dest_month or die "Failed to create path: $dest_month";
		}
	if ( !-d $dest_day ) 
		{
		print "Creating $dest_day\n";
    		make_path $dest_day or die "Failed to create path: $dest_day";
		}

	#### MOVE FILES #####
	move ($fp,$dest_file) or die "The move operation failed: $!";
	}

rclone

runscript.sh

  • Purpose:
    • make sure rclone isn't running
    • fetchmail, then check (if mail), pull out mime objects
    • run the perl to coordinate
    • run rclone to sync

Contents

if ps ax | grep -v grep | grep -v grep | grep rclone > /dev/null
then
    echo "RCLONE is running, let's not bind the system up"
else
    echo "RCLONE is not running"
fetchmail
cp /var/spool/mail/somedir/home/somedir/
echo 'd *' | mail -N
ripmime -i somedir -d /home/somedir/checkmail
rm /home/somedir/checkmail/text*
perl /home/somedir/movefiles.pl
# rclone copy /home/somedir/securitycameras rclone:securitycameras --transfers=40 --checkers=15 --tpslimit=10 --drive-chunk-size=1M --bwlimit 4M
rclone sync /home/somedir/securitycameras rclone:securitycameras --transfers=4 --checkers=2 --tpslimit=2 --drive-chunk-size=1M --bwlimit 4M
exit 0
fi