Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redmine-sync
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
redmine-sync
Commits
a7be6740
Commit
a7be6740
authored
10 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
added a few more pod items; started cleanup mode
parent
e56e3786
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Redmine/DB/CTX.pm
+28
-0
28 additions, 0 deletions
lib/Redmine/DB/CTX.pm
t_sync.pl
+45
-5
45 additions, 5 deletions
t_sync.pl
with
73 additions
and
5 deletions
lib/Redmine/DB/CTX.pm
+
28
−
0
View file @
a7be6740
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
t_sync.pl
+
45
−
5
View file @
a7be6740
...
@@ -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 in
s
tance'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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment