Child pages
  • UAPI Functions - Restore::restore_file
Skip to end of metadata
Go to start of metadata

Description

This function restores a file or directory from a backup to the file or directory's original location.

Examples


 cPanel or Webmail Session URL
https://hostname.example.com:2083/cpsessXXXXXXXXXXXX/execute/Restore/restore_file?backupID=2017-07-03&path=%2Fpublic_html%2Findex.php&overwrite=1


Note:

This example calls the UAPI function via a cPanel session. For more information, read our Guide to UAPI documentation. 

 LiveAPI PHP Class
$cpanel = new CPANEL(); // Connect to cPanel - only do this once.

// restore the file from a backup
$DAV = $cpanel->uapi(
    'Restore', 'restore_file',
    array(
        'backupID'  => '2017-07-03',
        'path' => '/public_html/index.php',
        'overwrite' => 1,
    )
 );


Note:

For more information, read our Guide to the LiveAPI System.

 LiveAPI Perl Module
my $cpliveapi = Cpanel::LiveAPI->new(); # Connect to cPanel - only do this once.

# restore the file from a backup
my $disable_shared_global_addressbook = $cpliveapi->uapi(
    'Restore', 'restore_file',
    {
        'backupID'  => '2017-07-03',
        'path' => '/public_html/index.php',
        'overwrite' => 1,
    }
 );


Note:

For more information, read our Guide to the LiveAPI System.

 cPanel Template Toolkit
<!--  restore the file from a backup -->
[% data = execute( 'Restore', 'restore_file'{ 'backupID' => '2017-07-03', 'path' => '/public_html/index.php', 'overwrite' => 1 } ); %]
[% FOREACH q = data %]
     <p>
         success: [% q.success %]
     </p>
[% END %]



Note:

For more information, read our Guide to Template Toolkit documentation. 

 Command Line
uapi --user=example Restore restore_file backupID=2017-07-03 path=/public_html/index.php overwrite=1


Notes:

  • You must URI-encode values.
  • username represents your account-level username.
  • For more information and additional output options, read our Guide to UAPI documentation or run the uapi --help command. 

 Output (JSON)
{
   "data":{
      "success":1
   },
   "warnings":null,
   "messages":null,
   "metadata":{

   },
   "errors":null,
   "status":1
}


Note:

Use cPanel's API Shell interface (cPanel >> Home >> Advanced >> API Shell) to directly test cPanel API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
backupIDstring

Required.

The backup's identification.

  • YYYY-MM-DD — Restore a daily backup from the specified backup date, in YYYY-MM-DD format.
  • monthly/YYYY-MM-DD — Restore a monthly backup from the specified backup date, in YYYY-MM-DD format.
  • weekly/YYYY-MM-DD — Restore a weekly backup from the specified backup date, in YYYY-MM-DD format.
  • incremental — Restore a daily incremental backup.
  • monthly/incremental — Restore a monthly incremental backup.
  • weekly/incremental — Restore a weekly incremental backup.

Note:

The YYYY-MM-DD format is a date in human-readable format, where:

  • YYYY is the year.
  • MM is the month.
  • DD is the day.
2017-07-03
pathstring

Required.

The file or directory's path, within a backup, that you wish to restore.

Notes:

  • The value of this parameter must begin with a forward slash (/).
  • We introduced this parameter in cPanel & WHM version 72.

Warning:

You must parse filenames properly to prevent a cross-site scripting (XSS) attack. 

A valid absolute path.

/public_html/index.php
overwriteBoolean

Required.

Whether to overwrite the file or directory on the disc with its backup replacement.

  • 1 — Overwrite the file or directory.
  • 0 — Do not overwrite the file or directory.
 1
fullpathstring

Required.

The file's fullpath, within a backup, that you wish to restore.

Notes:

  • The value of this parameter must begin with a forward slash (/).
  • We deprecated this parameter in cPanel & WHM version 72.

Warning:

You must parse filenames properly to prevent a cross-site scripting (XSS) attack.

A valid absolute path.

/public_html/index.php

Returns

ReturnTypeDescriptionPossible valuesExample
datahashA hash that contains the status of the operation.

This hash contains the success value.

 

success

Boolean

Whether the overwrite parameter succeeded.

This function returns this value under the data hash.

  • 1 — Success.
  • 0 — Failure.

1