Backup-Script for Pubman
Idea to create a Backup Script for Pubman[edit]
- Script is applicable for a Suse Linux
Set and Remove PID from Solution[edit]
Firstly you should modify your Jboss and Fedora script. On start of Jboss the PID must write in a file. And if the JBoss-Server will stopped that the PID of Jboss will removed.
Example for Jboss start:
echo $! > /var/run/jboss.pid
Example for Jboss stop:
rm -rf /var/run/jboss.pid
If Fedora and Jboss use a pid-file you can start with the backup script.
Stop solution, create a Snapshot and start solution[edit]
To get a consistence backup, the most secure way is to stop all used services, create a snapshot of the used data and start the services.
/etc/init.d/jboss stop /etc/init.d/fedora stop /etc/init.d/postgresql stop lvcreate --size 5000m --snapshot --name backupxy --permission r /dev/backup/backup /etc/init.d/postgresql start /etc/init.d/fedora start /etc/init.d/jboss start
Now you can create a consistent backup of your files
Backup all Files[edit]
Mount the snapshot
mount /dev/backup/backupxy
Add your backup routine for backupxy with rsync or what ever you want.
Umount the snapshot
umount /dev/backup/backupxy
And remove the backuped snapshot
lvremove -f /dev/backup/backupxy
Now you have a consistence backup of your System.
Additional modifcations for the backup script[edit]
Automatic backup[edit]
Create a cronjob for your backup script to run your backup in the same period.
Send Mail by problems[edit]
HOST=`hostname` MAILTO="mail@adresse"
Run the last command successfully? If not send mail[edit]
RC=$? if [ ! "${RC}" = "0" ]; then mail -s "Problem with ac: ${HOST} Status-RC=($RC)" ${MAILTO} </dev/null & exit fi
Run the last command successfully? If not send mail and recreate the snapshot of the volume[edit]
RC=$? if [ ! "${RC}" = "0" ]; then mail -s "${HOST} snapshot: lvcreate RC=($RC)" ${MAILTO} </dev/null & lvremove -f /dev/backup/backupxy lvcreate --size 3500m --snapshot --name backupxy --permission r /dev/backup/backup fi
Security feature to start the script if the last run was successful[edit]
If your script should only run after a successful backup, you can rename the script on start and set it backup on the end of the script.
mv backup.sh backup.sh0 mv backup.sh0 backup.sh