Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. db_host='localhost'
  4. db_user=''
  5. db_password=''
  6. databases='mstl'
  7. tmp_dir='/home/tmp'
  8. back_dir='/backup/mstl'
  9. work_dir='/home/mstl/public_html'
  10. backup_name='crm-loc'
  11. current_date=$(date +%d-%m-%Y)
  12. marker='/backup/do_not_remove_this_file'
  13.  
  14. # Check on tmp exist
  15. if ! [ -d ${tmp_dir} ];
  16.     then
  17.         mkdir -p ${tmp_dir}
  18. #        if ! [ -f ${tmp_dir} ];
  19. #            then
  20. #                echo 'can not create folder' >> backup_error.log
  21. #                exit
  22.     fi
  23. # Check on nfs mount
  24. if [ -f ${marker} ];
  25.     then
  26.         echo 'marker found and mount point is correct!'
  27.         # create mysql dump
  28.         mysqldump --host="$db_host" --user="$db_user" --password="$db_password" --databases ${databases[@]} > ${tmp_dir}/${backup_name}_dump-${current_date}.sql
  29.         mysql_dump=${backup_name}_dump-${current_date}.sql
  30.         # create files archive
  31.         tar -cf ${tmp_dir}/${backup_name}_${current_date}_files.tar -C ${work_dir} *
  32.         files_without_sql=${backup_name}_${current_date}_files.tar
  33.         # create full archive file  
  34.         tar -cjf ${tmp_dir}/${backup_name}_${current_date}_full.tar.bz2 -C ${tmp_dir} ${mysql_dump} ${files_without_sql}
  35.         full_archive=${tmp_dir}/${backup_name}_${current_date}_full.tar.bz2
  36.         # move full archive file and remove tmp files
  37.         mv ${full_archive} ${back_dir} & rm ${tmp_dir}/${files_without_sql} & rm ${tmp_dir}/${mysql_dump} $ rmdir ${tmp_dir}
  38.     else
  39.         echo ${current_date} 'marker do not found and mount point does not correct!' >> backup_error.log
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement