import Console;import mysql.client;//Local DatabaseConsole.log ("Connecting to local database server ...");varLocaldb,err =mysql.client (Server= "localhost"; UID= "Root"; PWD= "123456";); if(!localdb) {Console.log ("Failed to connect to database", Err)return;} Localdb.selectdb ("Blog"); Console.log ("Local Database connection succeeded"); //Remote DatabaseConsole.log ("Connecting to remote database server ...");varRemotedb,err =mysql.client (Server= "8.8.8.8"; UID= "XXXXX"; PWD= "XXXXX";); if(!remotedb) {Console.log ("Failed to connect to database", Err)return;} Remotedb.selectdb ("Blog"); Console.log ("Remote database connection succeeded"); //synchronizing local logs to remoteConsole.log ("Synchronize local log to remote");//Query Maximum IDvarresult = Remotedb.query ("Select Max (ID) as Maxid from Wp_posts");varremote_post_max_id = Result.fetchobject () ["Maxid"];//console.log ("Remote Maximum ID:" ++remote_post_max_id)Result.free ();//Query Localvarresult = Localdb.query ("Select ID from wp_posts where id>" + +ToString (remote_post_max_id));varLocal_post_sync_count =result.numrows (); Console.log ("Sync Required" + +local_post_sync_count) Result.free ();//Perform synchronization if(local_post_sync_count>0){//first replace the URLLocaldb.exec ("Update wp_posts set Post_content=replace (post_content, ' thinkai.net ', ' thinkai.net ') where id>" + +ToString (remote_post_max_id)); varresult = Localdb.query ("select * from wp_posts where id>" + +ToString (remote_post_max_id)); for(I=1; local_post_sync_count) {varrow =Result.fetchobject (); Console.log (String.Concat ("Sync ID:", row[' id '], "title:", row[' Post_title '])); Remotedb.exec (INSERT into wp_posts values (@ID, @post_author, @post_date, @post_date_gmt, @post_content, @post_title, @post_excerpt, @ Post_status, @comment_status, @ping_status, @post_password, @post_name, @to_ping, @pinged, @post_modified, @post_ MODIFIED_GMT, @post_content_filtered, @post_parent, @guid, @menu_order, @post_type, @post_mime_type, @comment_count) ", Row)}} //synchronize local log classification to remoteConsole.log ("Synchronize local log classification to remote");//Query Maximum IDvarresult = Remotedb.query ("Select Max (object_id) as Maxid from Wp_term_relationships");varremote_term_max_id = Result.fetchobject () ["Maxid"];result.free ();//Query Localvarresult = Localdb.query ("Select object_id from Wp_term_relationships where object_id>" + +ToString (remote_term_max_id));varLocal_term_sync_count =result.numrows (); Console.log ("Sync Required" + +local_term_sync_count) Result.free ();//Perform synchronization if(local_term_sync_count>0){varresult = Localdb.query ("select * from Wp_term_relationships where object_id>" + +ToString (remote_term_max_id)); for(I=1; local_term_sync_count) {varrow =Result.fetchobject (); Console.log (String.Concat ("Sync ID:", row[' object_id '])); Remotedb.exec ("INSERT into wp_term_relationships values (@object_id, @term_taxonomy_id, @term_order)", Row)}} //Synchronizing local taxonomy items to remoteConsole.log ("Synchronize local taxonomy items to remote");//Query Maximum IDvarresult = Remotedb.query ("Select Max (term_taxonomy_id) as Maxid from Wp_term_taxonomy");varremote_termt_max_id = Result.fetchobject () ["Maxid"];result.free ();//Query Localvarresult = Localdb.query ("Select term_taxonomy_id from wp_term_taxonomy where term_taxonomy_id>" + +ToString (remote_termt_max_id));varLocal_termt_sync_count =result.numrows (); Console.log ("Sync Required" + +local_termt_sync_count) Result.free ();//Perform synchronization if(local_termt_sync_count>0){varresult = Localdb.query ("select * from wp_term_taxonomy where term_taxonomy_id>" + +ToString (remote_termt_max_id)); for(I=1; local_termt_sync_count) {varrow =Result.fetchobject (); Console.log (String.Concat ("Sync ID:", row[' term_taxonomy_id '])); Remotedb.exec (INSERT into wp_term_taxonomy values (@term_taxonomy_id, @term_id, @taxonomy, @description, @parent, @count) ", Row)}}//Query Maximum IDvarresult = Remotedb.query ("Select Max (term_id) as Maxid from Wp_terms");varremote_term_max_id = Result.fetchobject () ["Maxid"];result.free ();//Query Localvarresult = Localdb.query ("Select term_id from Wp_terms where term_id>" + +ToString (remote_term_max_id));varLocal_term_sync_count =result.numrows (); Console.log ("Sync Required" + +local_term_sync_count) Result.free ();//Perform synchronization if(local_term_sync_count>0){varresult = Localdb.query ("select * from Wp_terms where term_id>" + +ToString (remote_term_max_id)); for(I=1; local_term_sync_count) {varrow =Result.fetchobject (); Console.log (String.Concat ("Sync ID:", row[' term_id '])); Remotedb.exec ("INSERT into wp_terms values (@term_id, @name, @slug, @term_group)", Row)}} Localdb.close (); Remotedb.close (); Console.pause ();
Local WordPress articles are written offline and synced to the remote (database only)