Restore cpanel incremental backups in ssh

If you try to restore incremental backups with pkgacct you’ll find at first the backup will not restore. An undocumented feature is you can rename the backup file to cpmove-username and then run restorepkg. In the default set up cpanel will also remove the backup file when done, with “Cleaning up extract directory”, so before the restore you can run chattr +i cpmove-username to keep the directory. When done run chattr -ia cpmove-username and move the folder back to its original name.

I wrote up a script that can be used to restore all incremental backups in a folder as well. Set DIR to be the full path where the files are located. The ARGS variable can be set with restorepkg options like –skipres and/or –force.


#!/bin/bash

DIR='/mnt/cpbackup/daily'
# add restorepkg args like --skipres --force
ARGS='';

cd $DIR
for i in *; do
#format username/cp/username
if [ -e $i/cp/$i ]; then
# rename backup
mv -v $i cpmove-$i
if [ ! -d cpmove-$i ]; then
echo "Error: cpmove-$i does not exist, is the file system read only?";
return;
fi
# otherwise cpanel will "Cleaning up extract directory" and remove the backup
chattr +iv cpmove-$i
/scripts/restorepkg $ARGS $DIR/cpmove-$i
# move backup file back
chattr -iv cpmove-$i
mv -v cpmove-$i $i
fi
done

Leave a Reply

Your email address will not be published. Required fields are marked *