copy_to_psql 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/local/bin/perl
  2. #
  3. # $Id$
  4. #
  5. # sc: ser control; tool for maintaining ser's databases
  6. #
  7. # History:
  8. # --------
  9. # 2003-04-07 initial attempt at file copy script
  10. #
  11. # To-DO:
  12. # -----
  13. # - generalization for other than mysql databases
  14. # - front-end to updating administrative mysql password would
  15. # be a convenient thing to have
  16. #
  17. # quick and dirty script to copy 0.8.10 mysql location and subscription table
  18. # out and create insert statements for postgres new CVS version table
  19. # this script only copies 2 tables, location and subscriber.
  20. # you may need to modify the open(FD,"sdfdsf") line to suite your needs.
  21. #
  22. $q = <<EOT;
  23. select
  24. user_id, domain, contact, expires, q, callid, cseq,
  25. last_modified
  26. from
  27. location
  28. EOT
  29. if(!open(FD,"/usr/local/mysql/bin/mysql --batch ser -e \"$q\"|"))
  30. {
  31. die("can't open mysql process");
  32. }
  33. print "/* insert location tuples */\n";
  34. print "delete from location;\n";
  35. while(<FD>)
  36. {
  37. chop;
  38. ($user_id,$domain,$contact,$expires,$q,$callid,$cseq, $lastmodified)=
  39. split("\t");
  40. $i = <<EOT;
  41. insert
  42. into
  43. location
  44. (
  45. username,
  46. domain,
  47. contact,
  48. expires,
  49. q,
  50. callid,
  51. cseq,
  52. last_modified,
  53. replicate,
  54. state
  55. )
  56. values
  57. (
  58. '$user_id',
  59. '$domain',
  60. '$contact',
  61. '$expires',
  62. $q,
  63. '$callid',
  64. $cseq,
  65. '$expires',
  66. null,
  67. null
  68. );
  69. EOT
  70. $i =~ s/\n/ /g;
  71. $i =~ s/\t+/ /g;
  72. $i =~ s/^\s+//;
  73. $i =~ s/\s+$//;
  74. print "$i\n";
  75. }
  76. $q = <<EOT;
  77. select
  78. phplib_id, user_id, password, first_name, last_name, phone,
  79. email_address, datetime_created, datetime_modified, confirmation,
  80. flag, sendnotification, greeting, ha1, domain, ha1b, perms,
  81. allow_find, timezone
  82. from
  83. subscriber
  84. EOT
  85. if(!open(FD,"/usr/local/mysql/bin/mysql --batch ser -e \"$q\"|"))
  86. {
  87. die("can't open mysql process");
  88. }
  89. print "/* insert subscriber tuples */\n";
  90. print "delete from subscriber;\n";
  91. while(<FD>)
  92. {
  93. chop;
  94. ( $phplib_id, $user_id, $password, $first_name, $last_name,
  95. $phone, $email_address, $datetime_created, $datetime_modified,
  96. $confirmation, $flag, $sendnotification, $greeting, $ha1,
  97. $domain, $ha1b, $perms, $allow_find, $timezone) =
  98. split("\t");
  99. $i = <<EOT;
  100. insert
  101. into
  102. subscriber
  103. (
  104. phplib_id, username, password, first_name,
  105. last_name, phone, email_address, datetime_created,
  106. datetime_modified, confirmation, flag,
  107. sendnotification, greeting, ha1, domain,
  108. ha1b, perms, allow_find, timezone
  109. )
  110. values
  111. (
  112. '$phplib_id', '$user_id', '$password', '$first_name',
  113. '$last_name', '$phone', '$email_address', '$datetime_created',
  114. '$datetime_created', '$confirmation', '$flag',
  115. '$sendnotification', '$greeting', '$ha1', '$domain',
  116. '$ha1b', '$perms', '$allow_find', '$timezone'
  117. );
  118. EOT
  119. $i =~ s/\n/ /g;
  120. $i =~ s/\t+/ /g;
  121. $i =~ s/^\s+//;
  122. $i =~ s/\s+$//;
  123. print "$i\n";
  124. }
  125. exit 0;