Jetserver – The Lazy Admin Blog
Home  /  cPanel • JetBackup  /  cPanel – Preventing users from downloading / restoring accounts

cPanel – Preventing users from downloading / restoring accounts

elialum September 16, 2018 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

About Author

elialum

Related Posts

  • JetBackup :: Restore on steroids !

    JetBackup :: Restore on steroids !

    August 21, 2020
  • cPanel :: Safely restore an account after enabling NGiNX

    cPanel :: Safely restore an account after enabling NGiNX

    May 23, 2019
  • Jetbackup :: Better safe then sorry

    Jetbackup :: Better safe then sorry

    January 20, 2019

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
Search in posts
Search in pages
Filter by Categories
Apache
CentOS
CloudLinux
cPanel
ESXI
iSCSI
JetBackup
Litespeed
MySQL
NGINX
Reduxio
SSL
Uncategorized
VMware
Wordpress
XEN

Tags

apache aspx backup CentOS cloudlinux cPanel CXS freetds google htaccess iscsi JetBackup Libmodsecurity litespeed modsec modsecurity mssql MySQL netapp nginx odbc php php.ini phpselector VMFS WHM xenserver

Popular Posts

  • How To Install & Configure a Galera Cluster with MySQL on Centos 7 February 6, 2018
  • Allow a cPanel server to run a VHOST from multiple IP addresses April 3, 2018
  • Libmodsecurity installation April 14, 2016
  • JetBackup Cheat Sheet :: Automatically Acknowledge Alerts November 15, 2018

Recent Posts

  • Dealing with aggressive bot scanners September 14, 2020
  • Litespeed Geo Location Redirect September 14, 2020
  • JetBackup :: Restore on steroids ! August 21, 2020
  • XENSERVER :: CONNECTING ISCSI SR NETAPP STORAGE September 4, 2019

Recent Comments

  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Oleg Drabkin on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Khan on Allow a cPanel server to run a VHOST from multiple IP addresses
  • Daniel on How To Install & Configure a Galera Cluster with MySQL on Centos 7
אחסון אתרים | JetApps