Similar to this Windows process to automatically move files to an off-KBOX location, I wanted a method to do the same in Red Hat with a cron job.
NOTE: For the purposes of this post, I didn't set any user restrictions on the folders or files where the KBOX backups are stored. You will probably want to modify this in your environment.
Steps to create the backup job:
- Log into the RHEL system as root.
- Create a location to download the files to. I used /kboxbackups.
- Change the permissions of that location by right clicking on the folder you created to allow access to the FTP shell script we are going to create later. I set mine like this:
- Open TextEdit and paste in the script from below. Modify it to reflect your KBOX IP and backup location under SERVER and BACKUPDIR respectively. I saved it as a .sh file in the /kboxbackups folder for ease of use. The actual name I used was: kbox-cron-backup-script-linux.sh
- Once saved, right click on your script and set permissions like the folder above. In this case, you will also need to check the box for "Allow executing file as program" or do this in terminal for the file: chmod 755 kbox-cron-backup-script-linux.sh
- Test the script by running it in terminal (sh kbox-cron-backup-script-linux.sh). It should put the backup files in the location you specified in a folder that shows today's date (YYMMDD format). The folder should have 2 files, kbox_dbdata.gz and kbox_file.tz
- Create the cron job by opening terminal and typing in: crontab -e -u root
- Type the letter "i". That allows you to insert text.
- Refer to this cron link for other options, I set mine to run at 4am every day with the string below:
00 04 * * * /kboxbackups/kbox-cron-backup-script-linux.sh
- Once you have inputted your parameters, press escape (Esc), then type : (colon), then wq and press Enter. It will look similar to the screenshot below before pressing enter after wq:
- If you are having trouble getting the cron job to run, you can add this to the following command to the string in #9 to the and it should give you direction on why it's not working: &>/kboxbackups/cron-output
- Once it's running successfully, you should have a folder and files like the screenshots on #6 above.
NOTE: These files will not truncate so it is important to delete them on a regular basis so it does not fill the FTP destination.
# remote server directory to upload backup to (on local machine)
# variable to get date
export NOW=`date +%y%m%d`
# make folder by date for backups
# login to K1000 and perform FTP download of backup files.
ftp -n -i $SERVER <<EOF
user $USERNAME $PASSWORD