Location: PHPKode > scripts > Cpanel cURL Backup > cpanel.backup.class.php
<?php	
	class CpanelBackup
	{
		public $cpanel_user; 
		public $cpanel_pass; 
		public $domain; 
		public $home_dir_backup = FALSE;
		public $databases = array();
		public $backup_store_location = "/";
		//Curl resource
		public $ch = FALSE;
		
		public function save_cpanel_backup()
		{						
			if($this->home_dir_backup == TRUE)
			{
				$file_name = "backup-".$this->domain."-home_root-".date("m-d-Y").".tar.gz";
			
				$params = "getbackup/".$file_name;			
				
				$this->save_backup_action($params,$file_name);
			}			
			if(count($this->databases))
			{
				foreach($this->databases as $database)
				{
					$params = "getsqlbackup/".$database.".sql.gz";
				
					$this->save_backup_action($params,FALSE,$database);
				}
			}	
			//Close the curl session
			curl_close($this->ch);				
		}
		private function save_backup_action($params,$file_name=FALSE,$database=FALSE)
		{
			if($database !== FALSE)
			{			
				$file_name = "backup-".$this->domain."-".$database."-".date("m-d-Y").".sql.gz";
			}
			//Set the URL location
			curl_setopt($this->ch, CURLOPT_URL, "http://www.".$this->domain.":2082/".$params);
			
			//No headers
			curl_setopt($this->ch, CURLOPT_HEADER, 0);
			
			//Return the output from the remote site
			curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
			
			//Open the file for writing make sure that you have permissions
			$fh = fopen($this->backup_store_location.$file_name, 'w');
			
			//Set where the backup contents of the file must be saved
			curl_setopt($this->ch, CURLOPT_FILE, $fh);						
			
			//Save the backup
			curl_exec($this->ch);			
		}
		public function cpanel_login()
		{
			//create a new cURL resource
			$ch = curl_init();
			
			//setting the curl session options
			curl_setopt($ch, CURLOPT_POSTFIELDS, "user=".$this->cpanel_user."&pass=".$this->cpanel_pass);
			curl_setopt($ch, CURLOPT_COOKIEJAR, 'Ocookie.txt');
			curl_setopt($ch, CURLOPT_URL, "http://www.".$this->domain.":2082/login/");
			curl_setopt($ch, CURLOPT_HEADER, 1);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

			curl_exec($ch);		
			return $this->ch = $ch;
		}
	}		
?>
Return current item: Cpanel cURL Backup