Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section General Discussion
  • Search

customize backup script

General questions about VestaCP
Post Reply
  • Print view
Advanced search
15 posts
  • Previous
  • 1
  • 2
dpeca
VestaCP Team
Posts: 473
Joined: Wed Nov 25, 2015 7:30 pm

Re: customize backup script
  • Quote

Post by dpeca » Wed Aug 24, 2016 10:06 pm

do you (or anybody) still need a script that will backup all databases (and only databases) ?
Top

dpeca
VestaCP Team
Posts: 473
Joined: Wed Nov 25, 2015 7:30 pm

Re: customize backup script
  • Quote

Post by dpeca » Thu Aug 25, 2016 12:15 am

@skurudo
I updated the script - viewtopic.php?f=10&t=12338&p=49399#p49399

I added three new options:

Code: Select all

use_absolute_full_path=1
backup_public_html=1
backup_public_shtml=0
For public_shtml it will add additional .shtml extension to backup archive file.
Top

moodup
Posts: 2
Joined: Mon Sep 19, 2016 8:51 am

Re: customize backup script
  • Quote

Post by moodup » Mon Sep 19, 2016 9:02 am

What with databases backup? I don't see code responsible for that.
Top

dpeca
VestaCP Team
Posts: 473
Joined: Wed Nov 25, 2015 7:30 pm

Re: customize backup script
  • Quote

Post by dpeca » Tue Sep 20, 2016 11:46 pm

Code: Select all

#!/bin/bash

if [ ! -d "/db-backups" ]; then
	eval "mkdir /db-backups"
	eval "chmod a-rwx /db-backups"
	eval "chmod u=rwx /db-backups"
fi

if [ ! -d "/db-backups-archive" ]; then
	eval "mkdir /db-backups-archive"
	eval "chmod a-rwx /db-backups-archive"
	eval "chmod u=rwx /db-backups-archive"
fi

rm /db-backups/*

cd /var/lib/mysql
for D in *; do
    if [ -d "${D}" ]; then
        D=${D//@002d/-}
        D=${D//@002e/.}
    # echo "${D}"   # your processing here
    mysqldump -h localhost ${D} | gzip > /db-backups/${D}_db_`date +"%Y%m%d%H"`.sql.gz
    fi
done

find /db-backups-archive/* -mtime +7 -exec rm {} \;

cd /db-backups
cp * /db-backups-archive

chmod a-rwx /backup.sh
chmod u=rwx /backup.sh

chmod -R a-rwx /db-backups
chmod -R u=rw /db-backups
chmod u=rwx /db-backups

chmod -R a-rwx /db-backups-archive
chmod -R u=rw /db-backups-archive
chmod u=rwx /db-backups-archive
Top

desfire
Posts: 24
Joined: Sun Jul 23, 2017 3:55 pm

Re: customize backup script
  • Quote

Post by desfire » Wed Jul 04, 2018 7:05 pm

dpeca wrote: ↑
Wed Aug 24, 2016 10:19 am
* 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
where do I place this code to make it work?
Top


Post Reply
  • Print view

15 posts
  • Previous
  • 1
  • 2

Return to “General Discussion”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password