Skip to content
Snippets Groups Projects
Commit a7be6740 authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

added a few more pod items; started cleanup mode

parent e56e3786
Branches
No related tags found
No related merge requests found
...@@ -41,6 +41,34 @@ sub sync_project ...@@ -41,6 +41,34 @@ sub sync_project
$ctx->sync_wiki ($sp_id, $dp_id); $ctx->sync_wiki ($sp_id, $dp_id);
} }
sub sync_cleanup_project
{
my $ctx= shift;
my $dp_id= shift;
my $dbh= $ctx->{'dst'}->connect();
return undef unless (defined ($dbh));
=begin comment
$ctx->{'tlt'}= undef;
not ready...
my @tables= qw(watchers);
foreach my $table (@tables)
{
my $ss_0= 'FROM `syncs` WHERE table_name=? AND
my $ss_1= "SELECT id
}
$ctx->{'tlt'}= undef;
=end comment
=cut
}
=head1 TRANSLATION =head1 TRANSLATION
Possibly the most important aspect of a synchronisation job is the Possibly the most important aspect of a synchronisation job is the
......
...@@ -9,13 +9,15 @@ use warnings; ...@@ -9,13 +9,15 @@ use warnings;
=head1 DESCRIPTION =head1 DESCRIPTION
Do stuff on a Redmine database. Used as an experimental sync-tool to Do stuff on a Redmine MySQL database. Used as an experimental sync-tool
migrate individual projects to another server. to migrate individual projects to another instance.
See https://github.com/gonter/redmine-sync See https://github.com/gonter/redmine-sync
=head1 OPERATION MODES =head1 OPERATION MODES
--mysql <src|dst> ... connect to source or destinance instance's MySQL databae
=cut =cut
use lib 'lib'; use lib 'lib';
...@@ -52,18 +54,29 @@ context". A "synchronisation context" needs to describe: ...@@ -52,18 +54,29 @@ context". A "synchronisation context" needs to describe:
my $setup_file; my $setup_file;
my $setup= my $setup=
{
'dst' =>
{
'config' => '/home/gg/etc/dst/database.yml',
'db' => 'production',
'attachment_base' => '/var/lib/redmine/default/files',
'attachment_with_directory' => 1, # Redmine version 2.x has that attribute
},
};
my $setup_OLD=
{ {
'src' => 'src' =>
{ {
'config' => '/home/gg/etc/src/database.yml', 'config' => '/home/gg/etc/src/database.yml',
'db' => 'production', 'db' => 'production',
'attachment_base' => '/home/backup/redmine-phaidra/files', 'attachment_base' => '/home/backup/redmine-phaidra/files',
'attachment_with_directory' => 0, # Redmine version 1.x does not have that attribute 'attachment_with_directory' => 0, # Redmine version 1.x does not have that attribute
}, },
'dst' => 'dst' =>
{ {
'config' => '/home/gg/etc/dst/database.yml', 'config' => '/home/gg/etc/dst/database.yml',
'db' => 'production', 'db' => 'production',
'attachment_base' => '/var/lib/redmine/default/files', 'attachment_base' => '/var/lib/redmine/default/files',
'attachment_with_directory' => 1, # Redmine version 2.x has that attribute 'attachment_with_directory' => 1, # Redmine version 2.x has that attribute
}, },
...@@ -105,6 +118,7 @@ while (my $arg= shift (@ARGV)) ...@@ -105,6 +118,7 @@ while (my $arg= shift (@ARGV))
foreach my $opt (@opts) foreach my $opt (@opts)
{ {
if ($opt eq 'h') { usage(); } if ($opt eq 'h') { usage(); }
elsif ($opt eq 'X') { $setup= $setup_OLD; }
else { die "unknown option [$opt]"; } else { die "unknown option [$opt]"; }
} }
} }
...@@ -156,7 +170,7 @@ elsif ($op_mode eq 'prep') ...@@ -156,7 +170,7 @@ elsif ($op_mode eq 'prep')
my $dst= read_configs($setup, 'dst'); my $dst= read_configs($setup, 'dst');
prepare_sync_table ($dst); prepare_sync_table ($dst);
} }
elsif ($op_mode eq 'sdp') # sdp: show destination intance's projects elsif ($op_mode eq 'sdp') # sdp: show destination instance's projects
{ {
my $dst= read_configs($setup, 'dst'); my $dst= read_configs($setup, 'dst');
...@@ -184,8 +198,10 @@ elsif ($op_mode eq 'user') ...@@ -184,8 +198,10 @@ elsif ($op_mode eq 'user')
{ {
my $target= shift (@parameters); my $target= shift (@parameters);
usage() unless (defined ($target)); usage() unless (defined ($target));
my $an= shift (@parameters); my $an= shift (@parameters);
usage() unless (defined ($an)); usage() unless (defined ($an));
my $cfg= read_configs($setup, $target); my $cfg= read_configs($setup, $target);
foreach my $av (@parameters) foreach my $av (@parameters)
...@@ -210,6 +226,21 @@ elsif ($op_mode eq 'syncuser') ...@@ -210,6 +226,21 @@ elsif ($op_mode eq 'syncuser')
$ctx->sync_user ($s_user_id, $res->{$s_user_id}); $ctx->sync_user ($s_user_id, $res->{$s_user_id});
} }
} }
elsif ($op_mode eq 'cleanup')
{
my $dst= read_configs($setup, 'dst');
my $ctx= new Redmine::DB::CTX ('ctx_id' => $setup->{'sync_context_id'}, 'dst' => $dst);
foreach my $sp (@{$setup->{'sync_projects'}})
{
# print "sp: ", Dumper ($sp);
print "not yet implemented\n";
# $ctx->sync_cleanup_project ($sp->{'dst_proj'});
}
print "\n"x3, '='x72, "\n", "Statistics:", Dumper ($ctx->{'stats'});
}
elsif ($op_mode eq 'sync') elsif ($op_mode eq 'sync')
{ {
my $src= read_configs($setup, 'src'); my $src= read_configs($setup, 'src');
...@@ -293,3 +324,12 @@ sub prepare_sync_table ...@@ -293,3 +324,12 @@ sub prepare_sync_table
$ddl_syncs, $ddl_syncs,
"--- >8 ---\n"; "--- >8 ---\n";
} }
__END__
=head1 TODO
* currently, only MySQL source and targets were used, supporting
PostgreSQL and/or sqlite would be nice as well
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment