[OLD]Simple Backup script using cPanel's backup script and BQbackups

Status
Not open for further replies.

Dan

Moderator
Please see updated script with new features here
------------------------------------------------------

Firstly I went through BQbackup's instructions which I will replicate here:

1) Log in through SSH. They talk about rsync and the access it has to files but I am not using rsync here as I wanted to be able to send one compressed file.

2) Create an RSA encryption key for use with the SSH transport. You may check if a key already exists by executing the following command:

# cat ~/.ssh/id_rsa.pub

If the file already exists, you may skip to step 3. Otherwise, create a key with the ssh-keygen utility:

# ssh-keygen -t rsa -N '' (note: these are two single quotes)

This is done so you do not have to supply a username and password. The key is not password protected here so be sure to keep it secure.

3) Copy your RSA encryption key to the BQ Internet backup system. You may do this through the shell as well.

# scp ~/.ssh/id_rsa.pub <bqbackupusername>@<bqbackupusername>.bqbackup.com :keys/server1

# ssh <bqbackupusername>@<bqbackupusername>.bqbackup.c om mergekeys

They have you name it server1 but I gave it my server's name instead. Up to you what you do here.

4 and 5) At this point they go into rsync and it's use but as stated I am not using rsync. The prior SCP commands had intrigued me so I did some digging and figured it would work very well for me.

Here is the script that I came up with. Text after a # is comments which do not effect the code in anyway.

Code:
#!/bin/sh
#This is a file to run the CPanel backup utility for each users home directory and then upload it to BQbackup.
#Four weeks of backups will be rotated and kept.
( ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com rm -rf week4
ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com mv week3 week4
ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com mv week2 week3
ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com mv week1 week2
ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com mkdir week1
ssh <bqbackupuser>@<bqbackupuser>.bqbackup.com mkdir week1/sqlbu
#Get a list of cpanel users, run backup, upload to BQbackups, then delete backup.
find /var/cpanel/users -type f -printf "%f\n" |
while read user; do
/scripts/pkgacct "$user"
scp /home/cpmove-"$user".tar.gz <bqbackupuser>@<bqbackupuser>.bqbackup.com:week1/
rm -f /home/cpmove-"$user".tar.gz
done
#Tar Apache config and shared applications then upload to BQbackup
tar -Pcf /home/apache-conf.tar.gz /usr/local/apache/conf;tar -Pcf /home/shared-htdocs.tar.gz /usr/local/share/htdocs
scp /home/*.gz <bqbackupuser>@<bqbackupuser>.bqbackup.com:week1/
rm -f /home/*.gz
#Upload SQL backups to BQbackup
scp /home/sqlbu/export/*gz <bqbackupuser>@<bqbackupuser>.bqbackup.com:week1/sqlbu/
)
Replace everything between <> with your pertinent information.

I chose to tar and backup my Apache config and my globally shared applications (Roundcube, Group-office, etc). You may not chose to do so, totally up to you of course.

The code shown is in a file named 'backups' which is called via cron. To create/save this file you first need to decide where to keep it. I keep it in a folder in my home directory in an attempt to avoid having bits and pieces scattered everywhere.

1) Copy and modify the code as needed using your own text editor then copy it to the clipboard.

2) Log in via SSH

3) Create a directory to keep such things in: mkdir /home/tools

4) Create the file: touch /home/tools/backups

5) Edit the file: pico /home/tools/backups

6) Paste the code into the file (right click should paste it in if you're using Putty).

7) Save the file and exit: control+x, y, enter

8) Make the file executeable: chmod 764 /home/tools/backups

9) Edit the crontab to run the file: crontab -e

10) This is the schedule I use: 0 2 * * 0 /home/tools/backups

This will run the file on Sundays at 2:00 AM. Modify as you like of course.

Here is a brief rundown of cron scheduling:

1 2 3 4 5

1 = Minutes (0-59)
2 = Hour (0-23 0=midnight)
3 = Day of month (1-31)
4 = Month (1-12)
5 = Day of week (0-6 0=Sunday)

And * is used to signify all. So * * * * * would execute every minute every hour etc.

11) Save the file and exit: Control+x, y, enter

Thanks to Josh, Khiltd, and KH-Paul for their input and direction on the script :)
 
I'm getting this error: Unable to get user id for user users at /scripts/pkgacct line 44.

Is that normal?
 
Josh,

Do you have "-type f" in the find line? If you don't then it will also return the folder name which is users.
 
When storing a backup like this, as opposed to rsync what exactly can be restored. Does this include all files and databases? Sounds like this covers pretty much everything, and leaves no need for rsync.
 
When storing a backup like this, as opposed to rsync what exactly can be restored. Does this include all files and databases? Sounds like this covers pretty much everything, and leaves no need for rsync.

Hello Sparky5693,

This does a full cPanel backup which includes everything needed to do a full restore for the account. So you wouldn't need to rsync anything except for stuff outside of your accounts that you wanted backed up.
 
With a backup of this nature, can you hand select individual files to restore, or is it an all or nothing type thing?
 
With a backup of this nature, can you hand select individual files to restore, or is it an all or nothing type thing?

Hello Sparky5693,

Good question! You will end up with a gzipped file which you can download and extract the files from and then move/upload to where ever need be :)
 
Perfect. Sounds like this is a much better than backing up with rsync. With this method, the backup server could be much smaller. Considering this is more than likely gonna be a "last resort backup", this would make a lot of sense.

It sounds like Bqbackup is the preferred name around here. Should I even bother looking around?
 
Perfect. Sounds like this is a much better than backing up with rsync. With this method, the backup server could be much smaller. Considering this is more than likely gonna be a "last resort backup", this would make a lot of sense.

It sounds like Bqbackup is the preferred name around here. Should I even bother looking around?

Oh it's always worth looking around although I wasn't able to find anything except Windows online storage.

If you find anything comparable be sure to let us know please!
 
Status
Not open for further replies.
Top