postgresqlbackup.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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"/pgsqlbackup.sh /usr/local/bin/
  26. chmod +x /usr/local/bin/pgsqlbackup.sh
  27. # configure
  28. echo -n "Please provide the postgresql host : "
  29. read _pg_host
  30. sed -i "s/HOST/$_pg_host/g" /usr/local/bin/pgsqlbackup.sh
  31. echo -n "Please provide the postgresql port : "
  32. read _pg_port
  33. sed -i "s/PORT/$_pg_port/g" /usr/local/bin/pgsqlbackup.sh
  34. echo -n "Please provide the postgresql user : "
  35. read _pg_user
  36. sed -i "s/USER/$_pg_user/g" /usr/local/bin/pgsqlbackup.sh
  37. echo -n "Please provide the postgresql passwd : "
  38. read _pg_passwd
  39. sed -i "s/PASSWD/$_pg_passwd/g" /usr/local/bin/pgsqlbackup.sh
  40. # creating crontab
  41. touch /var/spool/cron/crontabs/root
  42. crontab -l > /tmp/mycron
  43. echo "30 2 */2 * * /usr/local/bin/pgsqlbackup.sh" >> /tmp/mycron
  44. crontab /tmp/mycron
  45. rm /tmp/mycron