database.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //数据库备份
  2. function backup()
  3. {
  4. $("#info").remove();
  5. if(confirm(LANG['CONFIRM_BACKUP_DB']))
  6. {
  7. $.weeboxs.open("<div id='dump_result' style='line-height:80px; text-align:center; color:#f30;'>正在备份数据库</div>", {contentType:'text',showButton:false,title:"请勿刷新本页,请稍候...",width:500,height:80});
  8. dump_sql("",1,0,0);
  9. }
  10. }
  11. function dump_sql(filebase_name,vol,table_key,last_row)
  12. {
  13. var query = new Object();
  14. query.vol = vol;
  15. query.table_key = table_key;
  16. query.last_row = last_row;
  17. query.filebase_name = filebase_name;
  18. query.ajax= 1;
  19. $.ajax({
  20. url: ROOT+"?"+VAR_MODULE+"="+MODULE_NAME+"&"+VAR_ACTION+"=dump",
  21. data: query,
  22. dataType: "json",
  23. success: function(obj){
  24. if(obj.status)
  25. {
  26. if(obj.done==0)
  27. {
  28. $("#dump_result").html("数据备份中,共有"+obj.table_total+"张表,已备份"+obj.table_key+"张表,共"+(parseInt(obj.vol)-1)+"卷");
  29. dump_sql(obj.filebase_name,obj.vol,obj.table_key,obj.last_row);
  30. }
  31. else
  32. {
  33. $("#dump_result").html("数据备份成功,共"+obj.vol+"卷");
  34. location.reload();
  35. }
  36. }
  37. else
  38. {
  39. $("#dump_result").html(obj.info);
  40. }
  41. }
  42. ,
  43. error:function(ajaxobj)
  44. {
  45. // if(ajaxobj.responseText!='')
  46. // alert(ajaxobj.responseText);
  47. $("#dump_result").append("数据备份失败");
  48. }
  49. });
  50. }
  51. function restore_db_fun(filename,vol)
  52. {
  53. $.ajax({
  54. url: ROOT+"?"+VAR_MODULE+"="+MODULE_NAME+"&"+VAR_ACTION+"=restore&file="+filename,
  55. data: "vol="+vol+"&ajax=1",
  56. dataType: "json",
  57. success: function(obj){
  58. if(obj.status)
  59. {
  60. if(obj.done)
  61. {
  62. $("#restore_result").html("您已成功恢复数据库");
  63. location.reload();
  64. }
  65. else
  66. {
  67. $("#restore_result").html("正在恢复数据库备份"+obj.filename+"_"+obj.vol+".sql");
  68. restore_db_fun(obj.filename,obj.vol)
  69. }
  70. }
  71. else
  72. {
  73. $("#restore_result").html(obj.info);
  74. }
  75. }
  76. ,
  77. error:function(ajaxobj)
  78. {
  79. // if(ajaxobj.responseText!='')
  80. // alert(ajaxobj.responseText);
  81. $("#dump_result").append("数据恢复失败");
  82. }
  83. });
  84. }
  85. function restore_db(filename)
  86. {
  87. $("#info").remove();
  88. if(confirm(LANG['CONFIRM_RESTORE_DB']))
  89. {
  90. $.weeboxs.open("<div id='restore_result' style='line-height:80px; text-align:center; color:#f30;'>正在恢复数据库备份"+filename+"_1.sql</div>", {contentType:'text',showButton:false,title:"请勿刷新本页,请稍候...",width:500,height:80});
  91. restore_db_fun(filename,1);
  92. }
  93. }
  94. function delsql(filename)
  95. {
  96. if(confirm(LANG['CONFIRM_DELETE_DB']))
  97. $.ajax({
  98. url: ROOT+"?"+VAR_MODULE+"="+MODULE_NAME+"&"+VAR_ACTION+"=delete&file="+filename,
  99. data: "ajax=1",
  100. dataType: "json",
  101. success: function(obj){
  102. $("#info").html(obj.info);
  103. if(obj.status==1)
  104. location.href=location.href;
  105. }
  106. });
  107. }