[Digikam-users] moving albums from one hard disk to another

Luca Ferrari fluca1978 at infinito.it
Thu Jan 7 17:08:19 GMT 2016

Hi all,
this is what I've done and that seems to work fine so far:

1) rsync-ed the disks (with different uuids/mount points)
2) update the volume uuid in the database:
$ sqlite3 ~/Pictures/digikam4.db
> update AlbumsRoot set identifier='volumeid:uuid?<new_uuid>' where identifier=identifier='volumeid:uuid?<new_uuid>';
3) started digikam and took a look at the settings->collections to see
that the new mount point (and drive) is used. All images/tags seems in

With regard to (2) you can find new uuid by having a look at the /dev
filesystem (e.g., on linux /dev/disks/by-uuid). A backup of the .db
file is mandatory!

The following simple tiny Perl script could drive the user in the
above steps doing also a backup copy:

#!/usr/bin/env perl

use warnings;
use strict;
use DBI;
use v5.10;
use File::Copy;

my $digikam_db = "$ENV{HOME}/Pictures/digikam4.db";

my $dbh = DBI->connect(
    { RaiseError => 1 },
) or die $DBI::errstr;

# get all the available UUIDs stored in the database
my $sth = $dbh->prepare( 'SELECT distinct( identifier ) FROM AlbumRoots' );
my @uuids = $sth->fetchrow_array();

@uuids = map { local $_ = $_; s/(volumeid\:\?uuid=)(.*)/$2/; $_ } @uuids;

say "Found in the database ($digikam_db):";
for my $counter ( 0..$#uuids ){
    say "$counter) $uuids[ $counter ]";


my $selected_uuids_index = -1;
if ( @uuids == 1 ){
    $selected_uuids_index = 0;
    say "autoselecting unique UUID $uuids[ $selected_uuids_index ]";
    while ( $selected_uuids_index !~ /\d+/
        || $selected_uuids_index < 0
        || $selected_uuids_index > $#uuids ){
    say 'Please select which entry (a number between 0 and $#uuids): ';
    $selected_uuids_index = <STDIN>;
    chomp $selected_uuids_index;

    say "selected UUID $uuids[ $selected_uuids_index ]";

my $old_uuid = $uuids[ $selected_uuids_index ];

# ask the user the new uuid
my $new_uuid;
while ( ! $new_uuid ){
    say 'Please specify new uuid:';
    $new_uuid = <STDIN>;
    chomp $new_uuid;

    say "Substitute $old_uuid with $new_uuid (y/n)?";
    my $ok = <STDIN>;
    chomp $ok;
    say "you said $ok";
    $new_uuid = 0 if ( $ok !~ /^[y|Y]$/ );

$old_uuid = "volumeid:?uuid=$old_uuid";
$new_uuid = "volumeid:?uuid=$new_uuid";
my $update_query = "UPDATE AlbumRoots SET identifier=? WHERE identifier=?;";

say "Query $update_query";

say "Allow me to do a copy of the file";
my $backup_file = "$digikam_db.backup";
copy( $digikam_db, $backup_file ) || die "\nCannot do a backup copy,
say "Backup copy of the database done in $backup_file";

$sth = $dbh->prepare( $update_query );
$sth->bind_param( 1, $new_uuid );
$sth->bind_param( 2, $old_uuid );

say 'All done';

On Tue, Jan 5, 2016 at 9:40 AM, Luca Ferrari <fluca1978 at infinito.it> wrote:
> Hi all,
> I've digikam set-up to read images from a removable hard disk, I've
> around 10 albums on that for a 278GB of images.
> I'd like to change the hard disk with another one, with another label
> (and therefore mountpoint). What is the right way to replicate the
> images without loosing any digikam reference?
> Should I do an rsync and then what?
> Thanks,
> Luca

More information about the Digikam-users mailing list