20140128 recovering your dignity with perl - plembo/onemoretech GitHub Wiki
title: Recovering your dignity with perl link: https://onemoretech.wordpress.com/2014/01/28/recovering-your-dignity-with-perl/ author: phil2nc description: post_id: 6931 created: 2014/01/28 16:39:21 created_gmt: 2014/01/28 21:39:21 comment_status: closed post_name: recovering-your-dignity-with-perl status: publish post_type: post
Recovering your dignity with perl
Due to human error (mine), a boatload of user images got removed from our company address book. Some scripting magic saved the day. On the last day of the year a process that had never caused a problem ran and whacked the profile and thumbnail images of a large number of users in our company address book. To recover from this we unarchived our backup from the day before and then compared what we found with the existing state of things. Anything that was in the backup but not found in the live image folders was restored. Here's the perl script that did the job. [code language="perl" gutter="false"] #!/usr/bin/perl use strict; use List::Compare; my $todayprofdir = "/var/www/html/directory/public/img/profiles"; my $backupprofdir = "/data/tmp/profs-20131230"; my $todaythumbdir = "/var/www/html/directory/public/img/thumbails"; my $backupthumbdir = "/data/tmp/thumbs-20131230"; opendir(DIR, "$todayprofdir") or die $!; my @todayfiles = readdir DIR; closedir DIR; opendir(DIR, "$backupprofdir") or die $!; my @backupfiles = readdir DIR; closedir DIR; my $lc = List::Compare->new(@backupfiles, @todayfiles); my @backuponly = $lc->get_unique; my $count =0; foreach my $profname(@backuponly) { # print $profname, "\n"; $count++; my ($id, $extension) = split('_', $profname); my $thumbname = $id . ".jpg"; print $thumbname, "\n"; cp -f $backupprofdir/$profname $todayprofdir
; cp -f $backupthumbdir/$thumbname $todaythumbdir
; } print "Total unique: ", $count, "\n"; END; [/code]
Copyright 2004-2019 Phil Lembo