How to create a full backup of Plesk client data
The problem: Making a daily/weekly/monthly backup of your *nix Plesk server, with no other 3rd party tools involved.
Subrelated problem: The server may be pretty unresponsive during the backup process. We can avoid that by “niceing” the process.
The solution: We’ll use pleskbackup and some sh scripting. Our idea is to make a daily backup of all domains and settings, and keep the last 7 backups (as you will see you can modify the number of days to retain, the location, the backup name).
The backup file will have the day as a suffix, for an easier identification.
Also, the backups will be saved in a dedicated folder to ease the process of rsync to another server (syncing to Amazon S3 will follow).
#!/bin/sh
# Nice Plesk Backup
# (c) 2008 Frontline softworks, www.frontline.ro
# Visit http://sandbox.frontline.ro for updates
# Plesk Backup Utility Location
PleskBackup='/usr/local/psa/bin/pleskbackup'
# Backup folder
BackupFolder='/--plesk-backup/';
#Backup filename
BackupFileName='plesk-server';
#Backup extension
BackupExt='bak';
# Number of backups to keep
NrOfBackups=7;
# Generate the file names for the backups to keep (last NrOfBackups including today)
for (( i=0; i<$NrOfBackups; i++)); do
FileToKeep[$i]=`date --date=$i' day ago' +%Y%m%d`;
done
# Generate the complete path of the backup files to keep
for (( i=0;i<${#FileToKeep[@]};i++)); do
FileToKeep[$i]=$BackupFolder$BackupFileName-${FileToKeep[i]}.$BackupExt;
done
# Start PleskBackup Utility for current day, save to FileToKeep[0]
# We'll renice the process, to avoid server lockup during backup
# Other usefull parameters
# -v: Verbose (useful for debugging)
# --skip-logs: skips client logs
nice -15 $PleskBackup all ${FileToKeep[0]}
# Search the backup folder, and delete all the files older than last 'NrOfBackups' days
for file in `find $BackupFolder -type f -name $BackupFileName\*$BackupExt`; do
donotdelete=false;
for (( i=0;i<${#FileToKeep[@]};i++)); do
if [ "$file" = "${FileToKeep[i]}" ]; then
donotdelete=true;
fi
done
if [ "$donotdelete" = "false" ]; then
rm $file;
fi
done
Save the above script in /etc/cron.daily and wait for the daily run.
Have fun playing …
Tags: backup of the last given days, backup of your Plesk server, nice, Plesk, pleskbackup
One Response to “How to create a full backup of Plesk client data”
Leave a Reply















[...] script è sostanzialmente lo stesso pubblicato da Frontline Softwork, ma, essendo del 2008, contiene una sintassi non più valida per il Plesk. Ecco quindi che l'ho [...]