Page 1 of 2

customize backup script

Posted: Sun Aug 07, 2016 2:57 pm
by mehargags
Hi,
Can anyone help me customize or create a new Backup script that only:

1. Backs up domain/public_html/ from $user/web directory recursively
2. The Databases

and create a tarball of it

Don't need any user directories or vesta Specific Configuration backup.

Re: customize backup script

Posted: Thu Aug 11, 2016 2:59 pm
by skurudo
mehargags wrote: Don't need any user directories or vesta Specific Configuration backup.
So much wasted space?
Remember, about restore too... if custome backup, then you need custom restore ;-(

Re: customize backup script

Posted: Thu Aug 11, 2016 4:25 pm
by mehargags
skurudo wrote:
mehargags wrote: Don't need any user directories or vesta Specific Configuration backup.
So much wasted space?
Remember, about restore too... if custome backup, then you need custom restore ;-(
Yes no problems... I can always restore manually from the tarballs... vestaCP doesn't restore backups well for me either way.

All I just need is site files + DB only

Re: customize backup script

Posted: Mon Aug 22, 2016 8:39 am
by coolman
Any progress on this case? I need to customize backup too.

Current backup script does not follow symbolic links, so my backups are not complete. Here is my file structure:

/home/admin/web/site1 - has only several files and a symbolic link
/home/admin/web/site1/public_html --> /home/admin/web/template1
/home/admin/web/site2 - has only several files and a symbolic link
/home/admin/web/site2/public_html --> /home/admin/web/template1
/home/admin/web/site3 - has only several files and a symbolic link
/home/admin/web/site3/public_html --> /home/admin/web/template1
/home/admin/web/site4 - has only several files and a symbolic link
/home/admin/web/site4/public_html --> /home/admin/web/template2
/home/admin/web/site4 - has only several files and a symbolic link
/home/admin/web/site4/public_html --> /home/admin/web/template2
/home/admin/web/template1 - has a lot of files
/home/admin/web/template2 - has a lot of files

Current backup script only backs up /home/admin/web/site* directories and does not backup /home/admin/web/template* directories. How can I make it backup /home/admin/web/template* directories too?

Thanks

Re: customize backup script

Posted: Mon Aug 22, 2016 11:12 am
by mehargags
I'm getting it made myself with the help of another forum member dpeca, lets see if it goes well!

Re: customize backup script

Posted: Mon Aug 22, 2016 5:49 pm
by coolman
I found a workaround. I moved template files to /home/admin/template from /home/admin/web/template. Now template files backed up.

Re: customize backup script

Posted: Wed Aug 24, 2016 10:19 am
by dpeca
* UPDATED to v0.2 *

This will backup files from ALL websites in VestaCP (each of them as separated archive), and put tar file in /backup/manual/ folder as domain.com-YYYY-MM-DD.tar(.gz)

Code: Select all

#!/bin/bash

# Options:

backup_folder=/backup/manual

compress=0

exclude="--exclude='*/tmp/*' --exclude='*/temp/*' --exclude='*/log/*' --exclude='*/logs/*' --exclude='*/session/*' --exclude='*/sessions/*' --exclude='*/cache/*' --exclude='*/caches/*'"

use_absolute_full_path=1

backup_public_html=1
backup_public_shtml=0

################################################################################################################
# begin of script
#
# *** Script for backuping all VestaCP sites (only files) ***
#
# Created by dpeca (Predrag Damnjanovic - https://forum.vestacp.com/memberlist.php?mode=viewprofile&u=8116 )
# version: 0.2
#

if [ ! -d "$backup_folder" ]; then
	eval "mkdir $backup_folder"
fi

taroptions="cfP"
extension=tar
date=$(date +"%Y-%m-%d")

if [[ $compress -eq 1 ]]; then
	taroptions="czfP"
	extension=tar.gz
fi

function make_tar {
	folder=$1
	site=$2
	shtml=$3
	if [[ $shtml -eq 1 ]]; then
		site="$site.shtml"
	fi
	
	if [[ $use_absolute_full_path -eq 1 ]]; then
		command="tar $taroptions $backup_folder/$site-$date.$extension -C / $folder $exclude"
	else
		cd $folder
		command="tar $taroptions $backup_folder/$site-$date.$extension . $exclude"
	fi
	# echo $command
	eval $command
}


for name in /home/*
do
    if [ -d "$name" ]; then
		#echo $name/web
		if [ -d "$name/web" ]; then

			for name2 in $name/web
			do
				if [ -d "$name2" ]; then
					#echo $name2
					for name3 in $name2/*
					do
						if [[ $backup_public_html -eq 1 ]]; then
							folder=$name3/public_html
							site=$(basename $name3)
							if [ -d "$folder" ]; then
								make_tar $folder $site 0
							fi
						fi
						if [[ $backup_public_shtml -eq 1 ]]; then
							folder=$name3/public_shtml
							site=$(basename $name3)
							if [ -d "$folder" ]; then
								make_tar $folder $site 1
							fi
						fi
					done
				fi
			done
		fi
    fi
done

Re: customize backup script

Posted: Wed Aug 24, 2016 11:33 am
by mehargags
Works like a charm!!
thanks a ton dpeca

Re: customize backup script

Posted: Wed Aug 24, 2016 12:19 pm
by skurudo
Added as Idea -> https://bugs.vestacp.com/issues/364
I like this too ^_^

Re: customize backup script

Posted: Wed Aug 24, 2016 6:46 pm
by mehargags
skurudo wrote:Added as Idea -> https://bugs.vestacp.com/issues/364
I like this too ^_^
Thanks Skurudo for liking this and putting it as feature request... Sometimes all you need is a lean-mean Website dump only to quickly migrate to a new server or give the client his/her data. Will save alot of time!