• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Inctroducing incremental backup script - take a look

MislavO

Regular Pleskian
Hello.

What's the story? Why did I made this script?
Since I have like ~ 2TB of disk space used (500+ domains) on the server, fullbackup of every domain, every day was not an option for me, since fullbackup through Plesk had 140-150GB every day and basically 80% of all server disk space used were this backups. In addition, high load on the server untill backup process finished.

What did this script do for me?
Since I was keeping backups 10 days, this reduced my total disk space usage for 1,5TB, so in total, i'm around 500GB only now. Also, it reduced total backup process time during incremental days for 95%.

For who is this script for?
Plese note that this script is not something like Plesk scheduled backup and you on your own will have to manage this. What do I mean by that? Basically, in case you don't have knowledge in linux and commands, please don't use this script, use it on your own risk, especially if you will want to customize my script in some way. Also, if you will need to restore domain, you will have to do it manually as well.

What is this script doing then?
Before we start, I want to clear something:
- FULL backup means all files/folders are backuped full and incremental backup means only files/folders changed from last day are backuped; here is an example:
---> on full backup day you have e.g. 1GB of files, this will be backuped on that day, however, the next day, if you only changed 2 or 3 files, only those 2-3 files will be backuped, not the whole 1GB

Hope you got the point now, it's major disk space saver and that's basically the reason it was suggested already in community to implement this into the plesk itself.

Anyway, lets get started. What will this script do?
- script will make FULL backup one day and other six days, incremenetal backup (you decide when, which day, you want to do this FULL backup)
- script will run with lowest priority, so it won't cause any CPU problems (you can also change that)
- script will backup any location on the server you tell it
- script will send you email after it finish, each day it runs (doesn't matter if it's full backup day or incremental)
- you can adjust how many weeks you want to keep backups for (why weeks and not days? basically it's because this is weekly script, one day is fullbackup and other six are incremental, that's why I suggest you to set this to atleast one week or two) - after this, script itself will remove old backups
- script itself will create all daily/weekly directory and each day, backup will be placed in different directory, so you can easily search backups by days
- there is no incremental backups for mysql databases, they are backuped fully each day
- you can exlude domain/subscription from backup (this helps if you have like...own, personal domain/s with 60-70GB of data (or more) and for some reason you don't want to backup that)
- [in case I forgot something, i will add it later]

What this script won't do?
- as mentioned before, this script is nothing like current Plesk scheduled backup, so don't expect that I wrote something like that, if you don't like the script, don't use it, if you think it will help you, use it; I'm just sharing the script since I'm using it few weeks now on Plesk server and months on servers which don't have Plesk installed, as simple as that
- you won't be able to automatically restore backups, like you can do it now through plesk, you will have to do it manually
- script will not separate all backups like it's not, structure in /var/lib/psa/dumps, this include domains/clients/resellers and inside that additional folders, it will create two folders, one for databases, one for files, and everything will be inside of them
- [in case I forgot something, i will add it later]

Who can use this script and where?
If you don't have a big knowledge regarding anything in shell/terminal (it is recommended), you don't have to worry about that. Script itself is commented very well and will have to adjust some things, and you won't have any problems with that. As long as you don't change anything else without asking, it's fine, you won't do any harm. You can use this script basically anywhere...whether you have plesk installed or not, it doesn't make difference.

Lets get to the script already, shall we?
Alright alright, wall of text, lets get to most important part, script and files/settings/configuration you need to do:
- you will see in attachement two files (list_for_backup.txt and script.sh - more details later)

Lets take a look how is this working. Download both files and you can even test this on your local computer.

Open file "script.sh" and here is the configuration you need to do in order for script to work:
- line 11, variable "weekOLD", change number as you wish to keep backups for, change part 'X week ago', replace X with number you want, whether is that 1 or 2 or 3, etc. (as you can see, I'm using number 2, as 2 week ago)
- line 14, variable "pathOLD", this is your backup location on the server, set it as you want (I'm using same path as current backup location /var/lib/psa/dumps/backup - note that last backup folder? you need to create one if it doesn't exist - same goes for any other server location, this location MUST EXIST, script itself will not make this folder, since you decide where to put your backups)
- line 36, variable "pathLocal" - this path must be the same as "pathOLD"
- line 55-58, set you DB user/password - in script it's already implemented working user/password for Plesk, but there are also two lines, if you're planning it to test this on your local PC or other server
- line 64, variable "listBackup" - now this is one of the most important variables, you specify here file (second file in attachements) in which you tell script what do you want to backup (example is attached, DO NOT CHANGE format inside, first is name, then location, it must be in this order!!) - I've placed this script in my home folder, but it can be anywhere you want to, just specify location as you want to, don't forget to change file name as well, if you're rename-ing it; as you can see I'm backup all domains in /var/www/vhosts and mail folders
- line 69, variable "yourEmail" - enter your email here, on this email you will get daily report/log from backup script
- line 196, specify your weekday, in other words day when you want your fullbackup to execute (note: monday is 1, thuesday is 2, wednesday is 3) - in the script i'm using number 5, that is friday
- line 205 and 218 must be the same, read comments on line 198-204 in case you want to exclude something, if not, leave it as is

Two more notes:
- I'm still using the plesk scheduled backup to backup "Server configuration" (it's only ~ 20MBs), you can do the same
- please take some time, go through the all script and read up the comments, you can change some other things, like folder names

That's it! Run the script as (set chmod 744 to the script.sh file)
# cd /home/MYNAME && ./script.sh

You can put the same command in cron job as well.

Suggestions/critics are always welcomed. If you have any additional questions or you didn't understand something feel free to ask here or send me email to [email protected]

Use this script on your own risk and test it before you place it on the server.
 

Attachments

  • script_files.zip
    2.8 KB · Views: 68
Last edited:
Great job! I will closely monitor the reviews. Our Plesk backup responsible person will review it too.
 
IMO, a backup system is only as good as the restore system it comes with.

if I'd use this script and then have to recover something... would I have to manually restore the full backup and then every single incremental one one by one? I know a restore will not be used much, but it would still be a hazzle.

nontheless, I would love to see some additional forms of backup implemented into plesk

- full/differential/incremental
- add more options for the personal repository, like amazon s3 for example
 
IMO, a backup system is only as good as the restore system it comes with.

if I'd use this script and then have to recover something... would I have to manually restore the full backup and then every single incremental one one by one? I know a restore will not be used much, but it would still be a hazzle.

Like I said, you will have to do it manually and you on your own will have to manage this. If you have some knowledge like me, this won't take more then 2-3 minutes to unpack everything (depends of course on the size of the fullbackup itself - basically you copy backup one by one and extract it and that's it, you take DB backup from specific day you want to). On the other hand, I agree with you. Backup process and everything is done automatically, so in the near future, I will try to extend this script to handle restore automatically, then it would be "perfect".



nontheless, I would love to see some additional forms of backup implemented into plesk

- full/differential/incremental
- add more options for the personal repository, like amazon s3 for example

For plesk suggestions, take a look here:
http://forum.parallels.com/showthread.php?208520-Plesk-Backup-Restore-Survey
http://plesk.uservoice.com/forums/184549-feature-suggestions/suggestions/3539737-incremental-backup
 
Updated link to download and same archive added in attachments.

Script working as well on Plesk 11.5.
 
Nice script. We use hard-links instead to make a "time machine" and backup vhosts, mails and databases.
With hard links files are only stored once, but can be referenced from many directories.

E.g. very simple vhosts backup:

date=`date "+%Y-%m-%dT%H_%M_%S"`
HOME=/var/www/vhosts
DEST=/backup/vhosts

# use nice etc so that cpu and disksystem is not overloaded
nice -n 19 ionice -c2 -n7 rsync -a --delete --delete-excluded --exclude 'statistics' --link-dest=../current $HOME $DEST/incomplete_back-$date
mv $DEST/incomplete_back-$date $DEST/back-$date
rm -f $DEST/current
ln -s back-$date $DEST/current

# clean up old backups, e.g. more than 8 days old
for i in `find /backup/vhosts/ -maxdepth 1 -type d -mtime +8 -print`; do echo -e "Deleting directory $i";rm -rf $i; done


It would be nice it something like this could be integrated in the Plesk interface for backup/restore.
Today we have made scripts that our customers can activate themselves to restore from the newest backup.
 
Last edited:
Back
Top