How can I restore multiple accounts from cPanel backups (v.2)

postcd

Well-Known Member
Oct 22, 2010
717
19
68
Hello,

before a few years it was advised to restore multiple/all cpanel full backups at once at "WHM >> Backup >> Restore Multiple Backups", but such section is no longer there and in current Backup restoration sections i am unable to find the way to select all backups for that particular day be restored. In my case incremental backups. Thank you
 

postcd

Well-Known Member
Oct 22, 2010
717
19
68
Are You aware that i need to restore backups, not transfer current state of the cpanel accounts? I was unable to find that in the Transfer tool and in Backup Restoration sections. Where exactly it is that i can select which day backups to transfer&restore from old to new server (or from new server /backup dir) please and how to select ALL accounts not one by one doing 600+clicks?
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
Hello,

This is documented at:

Restore Multiple Backups

Thus, if you wanted to restore all backups from 08-31-2017 from the daily accounts backup directory, you'd use this command:

Code:
RESTORE_FROM_DATE="2017-08-31"; BACKUP_TYPE="daily"; if [ $BACKUP_TYPE="daily" ]; then BACKUP_BASE="/backup/$RESTORE_FROM_DATE/accounts/"; else BACKUP_BASE="/backup/$BACKUP_TYPE/"$RESTORE_FROM_DATE"/accounts/"; fi; for CP_ACC in $(find "$BACKUP_BASE" -type f -name '*.tar.gz' |awk -F/ '{print $5}' |sed 's/.tar.gz//g'); do /usr/local/cpanel/bin/backup_restore_manager add user="$CP_ACC" restore_point="$RESTORE_FROM_DATE" mail_config=1 mysql=1 subdomains=1; done
This will queue a restore for all backups in /backup/2017-08-31/accounts/. Simply update 08-31-2017 in the above command with the date associated with the backup directory you want to restore all accounts from. Then, browse to "WHM Home » Backup » Backup Restoration" and click on the "Restore" button at the bottom to begin restoring the queued backups.

Thank you.
 

abdelhost77

Well-Known Member
Apr 25, 2012
116
2
68
Morocco
cPanel Access Level
Root Administrator
Hello ,

unfortunately this do not work for me , only the first account is selectionned ( see below output)



RESTORE_FROM_DATE="2017-09-19"; BACKUP_TYPE="daily"; if [ $BACKUP_TYPE="daily" ]; then BACKUP_BASE="/backup/$RESTORE_FROM_DATE/accounts/"; else BACKUP_BASE="/backup/$BACKUP_TYPE/"$RESTORE_FROM_DATE"/accounts/"; fi; for CP_ACC in $(find "$BACKUP_BASE" -type f -name '*.tar.gz' |awk -F/ '{print $5}' |sed 's/.tar.gz//g'); do /usr/local/cpanel/bin/backup_restore_manager add user="$CP_ACC" restore_point="$RESTORE_FROM_DATE" mail_config=1 mysql=1 subdomains=1; done


info [backup_restore_manager] looking for /backup/2017-09-19/accounts/ananit/homedir
response:id=TQ:TaskQueue:7
reason = OK
result = 1
[[email protected] accounts]#
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
Hello,

For incremental backups, you'd need to update the command to look like this:

Code:
RESTORE_FROM_DATE="2017-09-19"; BACKUP_TYPE="daily"; if [ $BACKUP_TYPE="daily" ]; then BACKUP_BASE="/backup/$RESTORE_FROM_DATE/accounts/"; else BACKUP_BASE="/backup/$BACKUP_TYPE/"$RESTORE_FROM_DATE"/accounts/"; fi; for CP_ACC in $(find "$BACKUP_BASE" -maxdepth 1 -type d |awk -F/ '{print $5}' |sed 's/.tar.gz//g') ; do /usr/local/cpanel/bin/backup_restore_manager add user="$CP_ACC" restore_point="$RESTORE_FROM_DATE" mail_config=1 mysql=1 subdomains=1; done
Thank you.
 

Erik Knepfler

Member
Sep 2, 2014
19
1
53
Long Beach, California, United States
cPanel Access Level
Root Administrator
Why not just this (on target server):

cd ~
scp [email protected]:/backup/2018-02-08/accounts/* .
ls -1 *.tar.gz | sed -e 's/\.tar\.gz$//' | xargs /scripts/restorepkg --force
(note: this doesn't work because xargs doesn't like it for some reason. I'm sure someone smarter than me can fix it, I couldn't figure it out, something with the delimiter, xargs would only run one restorepkg command, and the sed wasn't needed at all. In the meantime I just made a .sh with a bunch of restorepkg commands for each filename.)

The "ls" line just uses sed to strip the .tar.gz from the filename and assumes what remains is the account name, which it should be, and pipes all these account names to restorepkg which seems nice.

or, even better I discovered, just scp over the .tar.gz files then move them into /backups/2018-02-08/accounts and then use WHM >> Backups >> Backup Restoration which will then see all those files?

Which is best?

@cPanelMichael your command is pretty complex, I haven't unpacked that so maybe you can explain how that might be better than this simple method, and also let me know if there are any pitfalls with either of these.

(Edit: for incrementals, multiple separate SCPs would be required to bring over the base backups and I don't know what other problems incrementals might introduce here.)
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,229
463
@cPanelMichael your command is pretty complex, I haven't unpacked that so maybe you can explain how that might be better than this simple method, and also let me know if there are any pitfalls with either of these.
Hi Erik,

The command I provided utilizes the WHM >> Backup Restoration queue. Thus, you can then utilize Web Host Manager to proceed with the restore process to more easily follow the progress and see any errors that occur during the restoration process.

Thank you.