mysqlbackup.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. echo -e '\033[35m
  3. __ __ _ ___ _
  4. | \/ |_ _ ___ __ _| | | _ ) __ _ __| |___ _ _ __ ___
  5. | |\/| | || (_-</ _ | | | _ \/ _ / _| / / || | _ (_-<
  6. |_| |_|\_, /__/\__, |_| |___/\__,_\__|_\_\\_,_| .__/__/
  7. |__/ |_| |_|
  8. \033[0m'
  9. if [ "$EUID" -ne 0 ]; then
  10. echo "Please run as root"
  11. exit
  12. fi
  13. # get the current position
  14. _cwd="$(pwd)"
  15. # check for assets forlder
  16. _assets="$_cwd/assets"
  17. if [ ! -d "$_assets" ]; then
  18. _assets="$_cwd/../assets"
  19. if [ ! -d "$_assets" ]; then
  20. echo "!! can't find assets directory !!"
  21. exit
  22. fi
  23. fi
  24. # adding the script
  25. cp "$_assets"/mysqlbackup.sh /usr/local/bin/
  26. chmod +x /usr/local/bin/mysqlbackup.sh
  27. # configure
  28. echo -n "Please provide the mysql root passwd : "
  29. read _root_mysql_passwd
  30. sed -i "s/ROOTPASSWD/$_root_mysql_passwd/g" /usr/local/bin/mysqlbackup.sh
  31. # creating crontab
  32. touch /var/spool/cron/crontabs/root
  33. crontab -l > /tmp/mycron
  34. echo "30 2 */2 * * /usr/local/bin/mysqlbackup.sh" >> /tmp/mycron
  35. crontab /tmp/mycron
  36. rm /tmp/mycron