PHP code example of houdunwang / backup

1. Go to this page and download the library: Download houdunwang/backup library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

houdunwang / backup example snippets


$config = [
	'size' => 20,//分卷大小单位KB
	'dir'  => 'backup/' . date( "Ymdhis" ),//备份目录
];

$status = \houdunwang\backup\Backup::backup( $config, function ( $result ) {
	if ( $result['status'] == 'run' ) {
		//备份进行中
		echo $result['message'];
		//刷新当前页面继续下次
		echo "<script>setTimeout(function(){location.href='{$_SERVER['REQUEST_URI']}'},1000);</script>";
	} else {
		//备份执行完毕
		echo $result['message'];
	}
} );
if ( $status === false ) {
	//备份过程出现错误
	echo \houdunwang\backup\Backup::getError();
}

$obj    = new \houdunwang\backup\Backup();
$status = $obj->recovery( $config, function ( $result ) {
	if ( $result['status'] == 'run' ) {
		//还原进行中
		echo $result['message'];
		//刷新当前页面继续执行
		echo "<script>setTimeout(function(){location.href='{$_SERVER['REQUEST_URI']}'},1000);</script>";
	} else {
		//还原执行完毕
		echo $result['message'];
	}
} );
if ( $status === false ) {
	//还原过程出现错误
	echo $obj->getError();
}