Page 1 of 1
backup before terminate
Posted: April 21st, 2021, 5:28 pm
by ludolugo
Hi
is it possible to run a backup at the moment a cpanel account is terminated? maybe a hook or something to make a snapshot? this because sometimes an account is terminated and the backup is almost 24 hours old. this is to cover our back in case of a support mistake
Re: backup before suspension
Posted: April 21st, 2021, 7:08 pm
by JetAppsRichard
Hello ludolugo,
Thank you for reaching out through our forums! Once a cPanel account is terminated, JetBackup 5 has an onTerminateHook that will automatically tag the account as an "Orphan Account" within the JetBackup Interface. Once an account is tagged as an orphan, no backups can/will be generated for this account.
You are able to add custom hooks to WHM/cPanel for the Account::Remove event. I would suggest creating a pre-hook that will run a backup on demand for the account before terminating the account. You can use our jetbackup5api within the cPanel hook in order to create a backup on demand. You will need the following information to do so:
1. First you will need to know the name of the username of the account being terminated. This can be gathered in the hook action code when the script is run. Follow the cPanel guide for creating hooks here:
https://documentation.cpanel.net/displa ... ized+Hooks
2. Once the account username is gathered, you can run the following command to get the Accounts Object Id from JetBackup 5.
Code: Select all
jetbackup5api -F listAccounts -D "filter=USERNAME"
3. After running this command you will be able to fetch the accounts _id from the response.
4. With the Accounts _id you can finally run the following command to create a backup on demand for that account.
Code: Select all
jetbackup5api -F createBackupOnDemand -D "account_id={_ID}"
Please note that Backup on Demand must be enabled in order for the API command to succeed. Please ensure that this is enabled in Settings -> Backup On Demand. For more information please visit our documentation for
Backup on Demand
Additionally, if you believe this should be a feature within JetBackup I highly recommend opening a new
Feature Request to gain votes. Our developers use the voting feature to gauge popularity for requests and the more votes a request has, the more likely it will be up for consideration.
If you have any more questions please let us know.
Re: backup before suspension
Posted: April 22nd, 2021, 12:49 pm
by elialum
Re: backup before suspension
Posted: April 27th, 2021, 4:51 pm
by ludolugo
Thanks JetAppsRichard and elialum
All of our servers have jetbackup 4 and as i understand jetbackup 4 can not execute a manual snapshot or backup on demand over cli, am i correct? or at least i couldn`t find it.
Re: backup before suspension
Posted: April 28th, 2021, 2:30 am
by JetAppsRichard
Hello ludolugo,
In order to manually execute a snapshot using JetBackup 4 API you would need to use the command `addQueueSnapshot` and pass it the username of the account. For example:
Code: Select all
jetapi backup -F addQueueSnapshot -D 'username=acct01'
You can more information about this command here:
https://docs.jetbackup.com/manual/whm-a ... pshot.html
Please note that the result from this command will add the snapshot to the queue in which jetbackup 4 executes every minute via the cron. In order to execute the snapshot immediately you will need to gather the snapshot _id from the result of the above command:
Code: Select all
success: 1
message: The selected account have been added to the snapshots queue.
system:
version: 4.0.25
tier: STABLE
type: cPanel
drMode:
agreement:
licenseIssue:
data:
_id: 6088aba5d6c44e3d00268822
...
Then run the following command with the gathered snapshot _id:
Code: Select all
/usr/bin/jetcli backup -vR snapshots -I {_id}
Please let us know if you require any further assistance.
Re: backup before terminate
Posted: April 29th, 2021, 8:44 am
by ludolugo
great, almost there...
as you said the queue snapshot executes every minute but if an account is terminated i guess it won`t work as the account doesn't exist anymore, what can i do in that case?
thanks
Re: backup before terminate
Posted: April 30th, 2021, 5:32 am
by JetAppsRichard
Hello,
In this case, you would need to execute the snapshot immediately after it has been queued. As mentioned in my last response, the addQueueSnapshot command will return the SNAPSHOT ID that you could then use to run the snapshot immediately with the following command:
Code: Select all
/usr/bin/jetcli backup -vR snapshots -I {_id}
The above command should execute in the shell that is created when the hook is triggered and the hook should not complete until after the snapshot is complete. Please give this a try and let us know if we can assist further.
Re: backup before terminate
Posted: May 1st, 2021, 10:40 am
by ludolugo
excellent, i'll give it a try.
thanks for the patience