Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- clear;
- # execute crontab -e and add line
- # 0 6 * * * script.sh
- # specifying constants
- LOGS_DIR=/var/log/;
- BACKUP_DIR=/var/backup;
- LINES=100;
- BACKUP_NAME="backup_"`date +%Y-%m-%d-%H-%M-%S.tar.gz`;
- # creation of backup folder
- mkdir -p /var/backup;
- # user root access checking
- if [ "$UID" -ne 0 ]
- then
- printf "Only users with root access can run this scripts.\n";
- exit 1;
- fi;
- # logs dir existence check
- cd $LOG_DIR || {
- printf "Logs directory is absent.\n" >&2;
- exit 1;
- }
- # archive creation (backup)
- (
- cd ..;
- tar cfz BACKUP_DIR/BACKUP_NAME "LOGS_DIR";
- );
- # logs cleaning
- rm -rf LOGS_DIR;
- mkdir -p LOGS_DIR;
- printf "Logs were backuped and after cleaned.\n";
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement