Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Hi guys I use centOS 64bit 5.7 and I need to create a backup script

What I want it to do:

  • screen -r example
  • command into java
  • pause for x amount of seconds
  • exit screen
  • zip/rar a folder which and put a timestamp on the name (with date) and move it to a different location
  • pause for duration of the zipping? If not a predetermined time.
  • screen -S example java -Xmx3g -Xincgc -jar server.jar nogui

Any ideas?

share|improve this question

2 Answers 2

I presume the screen requirement is so that you can initiate the backup process and then log out. If this is the case, disowning it will achieve the same thing.

Write a script that does all of the other stuff(zipping, filename with date, pausing, moving, etc.) and then start it in the background like so:

./my-backup-script.sh &

Then run:

disown

Then you can disconnect (or get disconnected by network issues) and the script will continue to run. It's worth making sure you redirect STDOUT and STDERR to files because once you disown the job, these two streams will be deleted.

share|improve this answer
    
so that "disown" gets put into the java command inside the screen? This makes me go back into ssh? –  Josip Gòdly Zirdum Dec 23 '11 at 14:04
    
No, disown should be used instead of screen and you run it manually after you have started the backup script. The only purpose of it is so that you can log out while the backup is running. Please let us know if my guess about why you wanted screen was wrong. –  Ladadadada Dec 23 '11 at 14:22
    
The thing is I plan to set this up as an automatic thing to happen via cronjob every hour. I can't do anything manually. The screen is used because it loads a program in java which has a console. –  Josip Gòdly Zirdum Dec 23 '11 at 16:26
    
The disown command won't be necessary if you start the script from a cron job. Cron jobs are designed to be run when you are not logged in. –  Ladadadada Dec 23 '11 at 16:49

Did it myself. Thanks anyway guys.

STAMP=`date +%d-%m-%Y_%H%M%S`

screen -x example -X stuff "`printf "command"`"
pause 10;
screen -x example -X stuff `printf "commandr"`
pause 10;
kill `pidof example`
tar -cvzf /directory/of/folder/I/want/backups/to/go/$STAMP-backup.tar.gz /directory/of/folder/I/want/backed/up/
screen -S example java -Xmx3g -Xincgc -jar server.jar nogui
screen -x example -X stuff `printf "save-on\r"`
screen -x example -X stuff `printf "save-all\r"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.