The Lazy Admin Blog

Home  /  cPanel • JetBackup  /  cPanel – Preventing users from downloading / restoring accounts

cPanel – Preventing users from downloading / restoring accounts

September 16, 2018 cPanel, JetBackup Leave a Comment

As hosting providers, you sometimes have to deal with huge account backups (over 100GB per account for example). JetBackup will make your life easier backing up these huge accounts, however restoring them is not always something we want to do.

Why would we want to prevent restoring huge accounts ?

When using JetBackup remote destinations, user’s data is saved directly on the backup destination, making your local space highly optimized. However, if you would like to perform a “cPanel full account restore”, JetBackup will first have to copy all the data into a temporary folder on your local drive, creating manually “cpmove” restore package and then executing cPanel’s internal restore command. This could easily consume your entire drive space, filling it up to 100%, and then the troubles will start 🙂

Best approach in these cases will be preventing users that match certain conditions from downloading / restoring their account, forcing them to contact you for these restore, so you can consider your actions in a safely manner.

Utilizing JetBackup hooks to prevent download / restore an account

In the following example we will learn how to create JetBackup hooks that will prevent accounts matching certain conditions from performing restore or download (or any other action we would like).

Step 1 :: Navigate to hooks page, click on “Create new hook”

Step 2 :: Create your “Download” hook

Hook name – name your hook for you to better understand it’s action.

Hook Position – Choose PRE so we can abort action before it starts

Hook type – Choose DOWNLOAD

Download Types – We choose “Accounts Files“, “Accounts Full“, this should cover all download scenarios

Hook Script – Put the path to your script, in the given example our script was PHP script so we used JetBackup’s internal php and executed our file with it – “/etc/jetapps/3rdparty/php70/bin/php-cgi -q /root/disklimithook.php”

DO THE SAME STEP AGAIN FOR THE RESTORE HOOK, UNDER “HOOK TYPE” CHOOSE “RESTORE”. You should now see two hooks in the hooks page, one for “download” and one for “restore”.

Working with our script

We linked our hook to “/etc/jetapps/3rdparty/php70/bin/php-cgi -q /root/disklimithook.php” script, here is the script –

#!/etc/jetapps/3rdparty/php70/bin/php-cgi -q
<?php

define('DISK_TO_ABORT', 5120000000); // 5Gb

$stdin = fopen('php://stdin', 'r');

$data = fread($stdin, 102400);

parse_str(urldecode($data), $output);

if(trim($output['stage']) == "onDownloadStart") {
$cmd = "jetapi backup -F getQueueItem -D \"_id=" . trim($output['queue_id']) . "\" -O json";
exec($cmd, $out, $exitCode);

if(!isset($out[0])) die(0);
$out = json_decode($out[0], true);
if($out === false) die(0);

$output = $out['data'];
}

$cmd = "/usr/bin/jetapi backup -F getAccount -D \"_id=" . trim($output['account']) . "\" -O json";
exec($cmd, $out, $exitCode);

if(!isset($out[0])) die(0);
$out = json_decode($out[0], true);
if($out === false) die(0);

if($out['success'] && intval($out['data']['disk_space_usage']) > DISK_TO_ABORT) {
fwrite(fopen('php://stderr', 'w'), "Aborting: " . trim($output['account']) . " disk size is greater then " . DISK_TO_ABORT . PHP_EOL);
die(1);
}

?>


This code gets the needed params from the hook, then checks the defined ‘DISK_TO_ABORT‘ value (in our case 5120000000 which are 5GB, you can change that). The script was written to handle either a download hook, or a restore hook to ease the use.

To work with the script simply copy & paste it and put at the following location – “/root/disklimithook.php” and it should work out of the box.

Testing the hooks – Let’s try to download from an affected account !

As you can see, our script returned “EXIT CODE 1” (false) so JetBackup aborted the action, download in that case.

For more information about JetBackup hooks, please see https://docs.jetbackup.com

 

Tags: cPanel, JetBackup
Previous Article
Next Article

Related Posts

  • Convert JetBackup to cPanel structure

    Convert JetBackup to cPanel structure

    October 6, 2022
  • Enable TLS 1.1/1.0 on cPanel servers

    Enable TLS 1.1/1.0 on cPanel servers

    September 30, 2022
  • Building your own private cloud with XenServer

    April 20, 2021

Leave a Reply

Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search Our Blog

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
Emails
ESXI
iSCSI
JetBackup
Linux
Litespeed
MySQL
NGINX
Oracle
Reduxio
Security
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup bash CentOS cloudlinux cPanel CXS Emails freetds google htaccess IMAP InnoDB iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc Oracle php php.ini phpselector rsync ssh ssmtp systemd threads VMFS WHM Wordpress xenserver

Popular Posts

  • Convert JetBackup to cPanel structure October 6, 2022
  • How To Install & Configure a Galera Cluster with MariaDB on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • rsync without prompting for password October 10, 2022

Recent Posts

  • Understanding Why More Threads Can Sometimes Slow Down Performance October 9, 2024
  • Set up a new systemd service May 18, 2024
  • Bash Arrays November 7, 2023
  • rsync without prompting for password October 10, 2022

Recent Comments

  • Sven on rsync without prompting for password
  • TheLazyAdmin on rsync without prompting for password
  • Sven on rsync without prompting for password
  • TheLazyAdmin on Convert JetBackup to cPanel structure
  • Chris on Convert JetBackup to cPanel structure
Privacy Policy • Contact