Dragons Hobbies Forum

General Category => Blogs => Topic started by: Dragon on October 15, 2016, 00:06:37

Title: Linux programs and Bash scripts to consolidate photos and begin a slideshow
Post by: Dragon on October 15, 2016, 00:06:37
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]
# Copy files from the Photos and Pictures directories of the Toshiba backup to my Sony Vaio HD.


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 ./
Title: Re: Linux programs and Bash scripts to consolidate photos and begin a slideshow
Post by: Dragon on October 16, 2016, 22:58:04
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.
Title: Re: Linux programs and Bash scripts to consolidate photos and begin a slideshow
Post by: Dragon on October 23, 2016, 19:24:46
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.
Title: Re: Linux programs and Bash scripts to consolidate photos and begin a slideshow
Post by: Dragon on April 28, 2019, 09:14:21
It had been a while since I've done any photo purging since we've been using Google Photos to store new pictures, but I wanted to get back to my old storage drives. I was going through some old photos recently and gthumb was being slow. My wife came in and was making some suggestions to be helpful and we talked some about what I was looking to do. My primary concern being that it needed to group photos using the folder structure of the native operating system rather than relying solely on database records that wouldn't be recognized on another computer without the same program.

While I continued to do some cleanup, my wife discovered a program called Digikam, which is an open source photo management tool that has a Duplicate finder along with other tools. I got it installed and although it still took a while to search through all the photos that I have, the Duplicates feature is very nice. Preview images of the photos along with the path to the photos are visible during the process. I have seen in other programs where you could select something like "Delete all except one" which I have NOT yet seen in Digikam, but aside from that, I've found it to be quite user friendly.

Changing the Album that a photo was in and renaming the photos does so on the native file structure. There is also a SQLite Database that stores information locally about the images. Options to update metadata on the actual files does exist, although it seems to be discouraged since it slows things down. Considering that I wanted to keep things useful outside of this application as much as possible, having a little slower response in order to have the metadata stored on the actual photo files seems like a good trade, although I haven't yet tried updating any metadata there.