Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'Data Protection' started by postcd, Aug 29, 2017.

Tags:
  1. postcd

    postcd Well-Known Member

    Joined:
    Oct 22, 2010
    Messages:
    689
    Likes Received:
    14
    Trophy Points:
    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
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Infopro

    Infopro cPanel Sr. Product Evangelist
    Staff Member

    Joined:
    May 20, 2003
    Messages:
    16,242
    Likes Received:
    385
    Trophy Points:
    583
    Location:
    Pennsylvania
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. postcd

    postcd Well-Known Member

    Joined:
    Oct 22, 2010
    Messages:
    689
    Likes Received:
    14
    Trophy Points:
    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?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #3 postcd, Aug 29, 2017
    Last edited: Aug 30, 2017
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,925
    Likes Received:
    1,815
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. abdelhost77

    abdelhost77 Well-Known Member

    Joined:
    Apr 25, 2012
    Messages:
    101
    Likes Received:
    2
    Trophy Points:
    68
    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
    [root@h10 accounts]#
     
  6. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,925
    Likes Received:
    1,815
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Erik Knepfler

    Erik Knepfler Member

    Joined:
    Sep 2, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Long Beach, California, United States
    cPanel Access Level:
    Root Administrator
    Why not just this (on target server):

    cd ~
    scp root@10.5.0.175:/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.)
     
    #7 Erik Knepfler, Feb 8, 2018
    Last edited: Feb 9, 2018
  8. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,925
    Likes Received:
    1,815
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice