Author Topic: Linux programs and Bash scripts to consolidate photos and begin a slideshow  (Read 631 times)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4476
  • Trogdor!
    • My Funagain Games Wishlist
Earlier this week, a backup drive of mine crashed... it doesn't seem to be recoverable without sending it to a specialist lab with a cleanroom. (I didn't know what a "cleanroom" was before this week, so obviously this isn't something that I'd have access to at work.) Anyway, I'm pretty sure that I've lost very little overall, if anything. It was one of 3 backup drives, but it failed the day after I had run an rsync process to copy over some files that were still missing from one of the 3.

Of course, I noticed that on my personal computer, I didn't have all the family photos that were available on the storage drive, even though I have plenty of space for them. To remedy that, I thought that now would be a good time to consolidate some photos, since they had been collected up in all different locations over the years. My personal computer is running Ubuntu Desktop 16.04 currently, while several other computers in the house over the years have primarily been Windows computers. Fortunately, two primary folder names have been used, regardless of which OS they were on - "Photos" and "Pictures".

To begin, I decided to create a text file containing all the paths with either of those names. Since I have my storage drive connected to my laptop under /mnt/toshiba, I opened up the command line and started the search there.

Code: [Select]
find /mnt/toshiba -name Photos >> DirectoryList-Photos.txt
find /mnt/toshiba -name Pictures >> DirectoryList-Pictures.txt

After creating those two files and verifying that the directories listed, I went on to creating the Bash script which would read through the files and, then use the paths listed on each line to copy everything to my Pictures directory on my laptop. One thing that I noticed before starting this part though, is that files with duplicate names are going to get overwritten. Since I want to due some purging of duplicates anyway, I'm not too concerned with that, but I am still going to tackle each list separately at least for partial separation between running my backups. Here is my Bash script:

Code: [Select]
#!/bin/bash
# Copy files from the Photos and Pictures directories of the Toshiba backup to my Sony Vaio HD.

SOURCES=/home/dragon/DirectoryList-Photos.txt
DESTDIR=/home/dragon/Pictures/

while read LINE; do
[ -z "$LINE" ] && continue # skip blank lines
rsync -avh --exclude='.*' "$LINE/" "$DESTDIR" --log-file=/home/dragon/rsync-toshiba-to-vaio.log
done < $SOURCES

Once that was done, I was able to jump into my Pictures directory and start up my slideshow with these commands:

Code: [Select]
cd ~/Pictures/
eog --slide-show ./
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4476
  • Trogdor!
    • My Funagain Games Wishlist
I found another Linux program for browsing images which looks pretty nice too... it's called gThumb Image Viewer.

Code: [Select]
sudo apt-get install gthumb
It has a Presentation mode, for running a slideshow, an Organization option, for grouping photos by date or other criteria (without moving them to new locations), and even a feature to Find Duplicates. Since I'm still moving files over to my laptop from my storage drive, I haven't tried all these features out yet, but I do intend to check them out soon.

One thing that I have already noticed about gThumb is that it loads up pretty quickly, much faster than the Nautilus File Manager when viewing a directory with hundreds of photos. On the flip side, it appears to have a delay detecting new files. Since I'm in the middle of copying 11 GB of images from one drive to another, I've noticed that several directories came up with a message of simply "(Empty)" even though I could navigate to the same directory through Nautilus and find plenty of files.
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)

Dragon

  • Administrator
  • Platinum Level
  • *****
  • Posts: 4476
  • Trogdor!
    • My Funagain Games Wishlist
Since my local hard drive had gotten filed up quickly, I had to change where my staging directory was going to be at. I have a 2TB drive mounted at /media/dragon/BluePortableDrive/ with a folder in there called PhotoStage. All of my files were copied there, then gthumb was used to remove the duplicate files which I did after copying smaller batches of files to the PhotoStage directory. Now that I've had some time to get all the files copied into a single directory, it's time for me to put them back to my storage drive with my consolidated location.

Code: [Select]
rsync -avh "/media/dragon/BluePortableDrive/PhotoStage/" "/mnt/toshiba/Photo/"
In order to handle the same process simply with our other Windows computers in the house, I've looked around for some "rsync for Windows" programs, but the ones that I found were just too cumbersome for what I wanted. Options like DeltaCopy and cwRsync were a couple that I noticed, but ultimately xcopy seemed to be the answer I was looking for. After using the Windows Map Network Drive to connect "V:" to my PhotoStage folder, I ran this simple command from Windows Command Line to start copying all of the files from my PhotoStage to the current directory of that PC:

Code: [Select]
xcopy V:\ *.* /e
Check out http://www.computerhope.com/xcopyhlp.htm to see more about the options and examples for using Windows xcopy.

Since I have another computer on our network that was able to connect to the root of our storage drive using "T:" having the slash at the end of the directory path to Photo caused a problem finding the path, so that xcopy command was just slightly different:

Code: [Select]
xcopy T:\Photo *.* /e
I've also found that robocopy is an updated version of xcopy that is also built into Windows. Syntax is slightly different, but I'm trying this another computer to copy the same files:

Code: [Select]
robocopy T:\Photo C:\Users\Public\Pictures /e
Since robocopy shows much more, such as percentage of file transfer, if it's a new file, and file size, just with this simple command, this is probably going to be the best method for setting up my automated tasks.  I also noticed that robocopy was able to complete the task more quickly, possibly because it was a different path, but even after twice as much time, the xcopy process hadn't completed and appeared to be hung up on transferring one specific video file. Looking into the new directory, I see that the subdirectories hadn't been copied at all, which was location of a majority of photos, so I just cancelled the task and ran robocopy on that computer instead also.
« Last Edit: October 23, 2016, 20:41:50 by Dragon »
"Hello IT. Have you tried turning it off and on again? ... OK, well, the button on the side. Is it glowing?... Yeah, you need to turn it on. Err, the button turns it on. Yeah, you do know how a button works, don't you? No, not on clothes." - Roy (The IT Crowd)