On Linux, backup operations via SSH may be required in various situations in cPanel. I will explain how to take backups faster using the "/scripts/pkgacct" script and how to transfer these backups to another server using the "/scripts/restorepkg" script.

For a normal website backup, follow these steps:

For example, let’s say the website "uzmanhosting.net.tr" has the username "uzman".

To take a backup:

/scripts/pkgacct turkiye

Simply running this command will start backing up the account for user "turkiye" immediately, and save the backup file compressed in "tar.gz" format under the "/home" directory. The file will be named "cpmove-turkiye.tar.gz" in the "/home" directory.

You can transfer the backup file to another server using RSYNC or SCP methods and place it again in the "/home" directory. Then, use the "/scripts/restorepkg" program to restore the backup.

To restore on the second server, move the "cpmove-turkiye.tar.gz" file to the "/home" directory and run:

/scripts/restorepkg turkiye

When you run this command on the second server, it will look for a backup named "turkiye" in specific directories ("/home", "/root", etc.) and start the restoration process once found.

With these two scripts, you can perform backup and restore operations much faster. Now, I will explain how to backup the entire server using the same method, transfer it to another server, and restore it.

For this, we will use the "for" loop.

To backup the entire server using the "/scripts/pkgacct" script, run the following command:

for b in $(ls /var/cpanel/users); do /scripts/pkgacct $b; done

This command will start backing up all users, collecting them from "/var/cpanel/users" and saving the backups to the "/home" directory in the "cpmove-USER.tar.gz" format.

After all backups are done, I will transfer the sites using SCP. Suppose the example IP address is "10.0.0.3":
cd /home
scp cpmove-* root@10.0.0.3:/home

If the destination server’s IP is 10.0.0.3 and the SSH port is different from 22, for example 9980, use this command:
cd /home
scp -P9980 cpmove-* root@10.0.0.3:/home

After that, all backups will be transferred to the second server. Once the transfer is complete, you can restore all backups using the "/scripts/restorepkg" script. You can do this with a "for" loop:
cd /home
for r in $(ls | grep tar.gz | cut -d- -f2 | cut -d. -f1); do /scripts/restorepkg $r; done

This command filters the output of "ls -la" to remove "cpmove" and the "tar.gz" extensions, leaving only the usernames, and sequentially passes them as parameters to the "restorepkg" script. This way, all backups transferred to the new server will be restored one by one without waiting.

This backup method can be very useful for systems where the disk structure is corrupted or not repaired by FSCK. Also, it can save time during normal server migrations as it is faster than other methods.


#hostingturkiye #Backup #FastBackup #LinuxSSH #cPanel #Restore #RSYNC #SCP #ServerMigration #BackupMethods #ForLoop #DiskBackup #FSCK #WebHosting #SiteSecurity #DataBackup #Technology #SEO #DigitalMarketing

Did you find it useful?
(39 times viewed / 0 people found it helpful)