Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- db_host='localhost'
- db_user=''
- db_password=''
- databases='mstl'
- tmp_dir='/home/tmp'
- back_dir='/backup/mstl'
- work_dir='/home/mstl/public_html'
- backup_name='crm-loc'
- current_date=$(date +%d-%m-%Y)
- marker='/backup/do_not_remove_this_file'
- # Check on tmp exist
- if ! [ -d ${tmp_dir} ];
- then
- mkdir -p ${tmp_dir}
- # if ! [ -f ${tmp_dir} ];
- # then
- # echo 'can not create folder' >> backup_error.log
- # exit
- fi
- # Check on nfs mount
- if [ -f ${marker} ];
- then
- echo 'marker found and mount point is correct!'
- # create mysql dump
- mysqldump --host="$db_host" --user="$db_user" --password="$db_password" --databases ${databases[@]} > ${tmp_dir}/${backup_name}_dump-${current_date}.sql
- mysql_dump=${backup_name}_dump-${current_date}.sql
- # create files archive
- tar -cf ${tmp_dir}/${backup_name}_${current_date}_files.tar -C ${work_dir} *
- files_without_sql=${backup_name}_${current_date}_files.tar
- # create full archive file
- tar -cjf ${tmp_dir}/${backup_name}_${current_date}_full.tar.bz2 -C ${tmp_dir} ${mysql_dump} ${files_without_sql}
- full_archive=${tmp_dir}/${backup_name}_${current_date}_full.tar.bz2
- # move full archive file and remove tmp files
- mv ${full_archive} ${back_dir} & rm ${tmp_dir}/${files_without_sql} & rm ${tmp_dir}/${mysql_dump} $ rmdir ${tmp_dir}
- else
- echo ${current_date} 'marker do not found and mount point does not correct!' >> backup_error.log
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement