Advertisement
Guest User

Untitled

a guest
May 28th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. #!/bin/bash
  2. clear;
  3. # execute crontab -e and add line
  4. # 0 6 * * * script.sh
  5.  
  6. # specifying constants
  7. LOGS_DIR=/var/log/;
  8. BACKUP_DIR=/var/backup;
  9. LINES=100;
  10. BACKUP_NAME="backup_"`date +%Y-%m-%d-%H-%M-%S.tar.gz`;
  11.  
  12. # creation of backup folder
  13. mkdir -p /var/backup;
  14.  
  15. # user root access checking
  16. if [ "$UID" -ne 0 ]
  17.     then
  18.         printf "Only users with root access can run this scripts.\n";
  19.         exit 1;
  20.     fi;
  21.  
  22. # logs dir existence check
  23. cd $LOG_DIR || {
  24.     printf "Logs directory is absent.\n" >&2;
  25.     exit 1;
  26. }
  27.  
  28. # archive creation (backup)
  29. (
  30.     cd ..;
  31.     tar cfz BACKUP_DIR/BACKUP_NAME "LOGS_DIR";
  32. );
  33.  
  34. # logs cleaning
  35. rm -rf LOGS_DIR;
  36. mkdir -p LOGS_DIR;
  37.  
  38. printf "Logs were backuped and after cleaned.\n";
  39.  
  40. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement