{"id":2261,"date":"2019-01-02T10:19:44","date_gmt":"2019-01-02T10:19:44","guid":{"rendered":"http:\/\/www.softaculous.com\/blog\/docs\/api\/restore-backup-api\/"},"modified":"2021-07-02T04:42:26","modified_gmt":"2021-07-02T04:42:26","slug":"restore-backup-api","status":"publish","type":"docs","link":"https:\/\/www.softaculous.com\/blog\/docs\/api\/restore-backup-api\/","title":{"rendered":"Restore Backup API"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Overview<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If you wish to automate the Restoration of Backup using a different software, you can do that in Softaculous as there is an API Class which enables us to do so.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">API Class<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can find the API Class in your Softaculous folder e.g. in cPanel its located here\u00a0:<\/p>\n\n\n\n<p class=\"bash hljs wp-block-paragraph\">\/usr\/local\/cpanel\/whostmgr\/docroot\/cgi\/softaculous\/enduser\/sdk.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">OR<br>You can find it here and place it into above mentioned path:<br><a href=\"https:\/\/softaculous.com\/docs\/File:Softaculous_Development_Kit.zip\">File:Softaculous Development Kit.zip<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding the API<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The API is a simple class which will pass the data to Softaculous to restore a backup. Here is an example to restore a backup&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">&lt;?php\n@set_time_limit(100);\n\ninclude_once('sdk.php');\n\n$new = new Softaculous_API();\n$new-&gt;login = 'https:\/\/username:password@domain.com:2083\/frontend\/x3\/softaculous\/index.live.php';\n\n\/\/ Default is serialize if nothing is specified\n$new-&gt;format = 'serialize'; \/\/ There are three kind of formats available. [serialize][json][xml]. \n\n$data['restore_dir'] = 1; \/\/ Restore Directory\n$data['restore_db'] = 1; \/\/ Restore Database\n$data['restore_datadir'] = 0; \/\/ Restore Data Directory\n$data['restore_wwwdir'] = 0; \/\/ Restore WWW Directory\n\n$res = $new-&gt;restore('wp.26_60832.2012-07-26_10-13-33.zip', $data); \/\/ Restore API Call\n\n$res = unserialize($res); \/\/ Get into Array\nif(!empty($res['done'])){ \/\/ if $res['done'] == 1, restore was completed successfully\n\techo 'Restored';\n}else{\n\techo 'Restoration Failed';\n\tprint_r($res['error']); \/\/ Print the error\n}\n?&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">As you may see this will Restore the wp.26_60832.2012-07-26_10-13-33.zip Backup.&nbsp;<br><br>Lets go through the Code&nbsp;:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Initializing and Authentication<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">$new = new Softaculous_API();\n$new-&gt;login = 'https:\/\/username:password@domain.com:2083\/frontend\/x3\/softaculous\/index.live.php';<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will load the Class in $new and we are setting the LOGIN URL as without authentication you will not be able to access Softaculous. The code here is an example to Restore Backup in cPanel. cPanel allows User Authentication via the URL itself and many other panels also.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">'https:\/\/username:password@domain.com:2083<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If your panel has some different method, you must first implement that code and then proceed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Dont send emails<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If you want no emails to be sent by Softaculous on the installation of a script please pass the&nbsp;<strong>&amp;noemail=1&amp;<\/strong>&nbsp;in the login url. e.g&nbsp;:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">$new-&gt;login = 'http:\/\/user:password@domain.com:2082\/frontend\/x3\/softaculous\/index.live.php?&amp;noemail=1&amp;';<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Result Format<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Result format can be in three types: Serialize, XML &amp; JSON. Here we are taking example of serialize<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">\/\/ Default is serialize if nothing is specified\n$new-&gt;format = 'serialize'; \/\/ There are three kind of formats available. [serialize][json][xml].<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Data Fields<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Softaculous will expect you to submit the data fields as it shows during the installation of Scripts. Now most scripts have common fields like&nbsp;<strong>restore_dir<\/strong>&nbsp;and&nbsp;<strong>restore_db<\/strong>&nbsp;and stuff like that. The possible values these can be&nbsp;<strong>0<\/strong>&nbsp;and&nbsp;<strong>1<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">$data['restore_dir'] = 1; \/\/ Restore Directory\n$data['restore_db'] = 1; \/\/ Restore Database\n$data['restore_datadir'] = 0; \/\/ Restore Data Directory\n$data['restore_wwwdir'] = 0; \/\/ Restore WWW Directory\n$res = $new-&gt;restore('wp.26_60832.2012-07-26_10-13-33.zip', $data);<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The above code is just setting to Restore Directory, Database, Data Directory &amp; WWW Directory<br>The line&nbsp;<strong>$res = $new-&gt;restore(&#8216;wp.26_60832.2012-07-26_10-13-33.zip&#8217;, $data);<\/strong>&nbsp;will start the restoration process and $res will have the result that is obtained.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">List Backups<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">By following code you can get the list of backups<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">$backups = $new-&gt;list_backups();<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Return Values<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">If the response is in the serialize format we can unserialize it and get the output in array.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted php hljs\">$res = unserialize($res);\nif(!empty($res['done'])){\n\techo 'Restored';\n}else{\n\techo 'Restoration Failed&lt;br\/&gt;';\n\tprint_r($res['error']);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">On a successful restore,&nbsp;<strong>$res[&#8216;done&#8217;]<\/strong>&nbsp;will have the value&nbsp;<strong>1<\/strong>&nbsp;<br>On error, array&nbsp;<strong>$res[&#8216;error&#8217;]<\/strong>&nbsp;is returned with the error details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Support<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can always ask us if you have any queries. The support department can be accessed from here&nbsp;:&nbsp;<a href=\"https:\/\/www.softaculous.net\/support\/\">https:\/\/www.softaculous.net\/support\/<\/a><\/p>\n","protected":false},"featured_media":0,"parent":1683,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","docs_category":[],"class_list":["post-2261","docs","type-docs","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs\/2261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/comments?post=2261"}],"version-history":[{"count":2,"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs\/2261\/revisions"}],"predecessor-version":[{"id":2852,"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs\/2261\/revisions\/2852"}],"up":[{"embeddable":true,"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs\/1683"}],"wp:attachment":[{"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/media?parent=2261"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/www.softaculous.com\/blog\/wp-json\/wp\/v2\/docs_category?post=2261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}