#!/bin/bash

	DATE=$(date +"%Y%m%d")
	DST="/home/backup/publichtml"
	LOG_BACKUP="/var/log/backup_edokumenty"
	ENV="edokumenty"

	DATESTART=$(date +"%Y-%m-%d %H:%M:%S")
	
	mkdir -p ${LOG_BACKUP}

	if [ -d $DST ] 
	then
		sleep 1
		else
			mkdir $DST
			fi


	echo "Start: Backup public_html ${ENV} - ${DATESTART}"  >> ${LOG_BACKUP}/backup_public_html_${ENV}.log


		cd /home/edokumenty/
			tar -pczf public_html.tar.gz public_html/ vendor/ src/ lib/ bin/ etc/ 
			mv public_html.tar.gz ${DST}/public_html_${DATE}.tar.gz
			
	#Usunięcie plikow starszych niż 4
		find ${DST} -name "public_html*.tar.gz" -mtime +4 -type f -delete

	DATEEND=$(date +"%Y-%m-%d %H:%M:%S")

	echo "Koniec: Backup public_html ${ENV} - ${DATEEND}" >> ${LOG_BACKUP}/backup_public_html_${ENV}.log
