Want to backup dirs on application start and close.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to backup dirs on application start and close.
# 1  
Old 01-24-2016
Code Want to backup dirs on application start and close.

Hi

I want to write a script that will back up one directory if a certain application launches and then backs up another directory if that same application is closed down.

NFI where to start. It seems like cron isn't the tool for this because that is time based. I'm thinking I need something that is constantly running in the background looking for the process to begin/end, or, something in the applications own directory that is triggered when it runs/closes.

Any prod in the right direction greatly appreciated, also, ELI5.
# 2  
Old 01-24-2016
For something like this, we really need to know what operating system and shell you're using. (And, it helps to know what operating system and shell you're using for almost every question posted to the Shell Programming and Scripting forum. To save you and us time, please get into the habit of providing this information whenever you start a new thread in this forum.)
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 01-24-2016
Hi Don

I'm running KX Studio, an ubuntu based distro using bash.
# 4  
Old 01-24-2016
Do you have write access to the application (so the backup can be built into it), or could you create a wrapper that, when run, does the backup and then lauches the application?

---------- Post updated at 10:53 ---------- Previous update was at 10:52 ----------

How is the application launched?
# 5  
Old 01-24-2016
Not sure what write access to an application is, not skilled enough to create a wrapper. The application is invoked by either typing its name at the console (ardour4) or by double clicking an icon in the GUI.
# 6  
Old 01-24-2016
Heya

Create (if not exists yet): $HOME/bin
Save the following as $HOME/bin/myardour4
Obvously you should change the DIR_* variables to match your needs.
Code:
#!/bin/bash
#
#	Variables
#
	DIR_BASE=~/tmp		# Directory holding the content to save
	DIR_BKUP=./tester	# Directory to be saved
	DIR_TRGT=~/backups	# Directory to store the tarball
	NOW=$(date +'%F_%T'|sed s,":",".",g)	# Prepare string: YYYY-MM-DD_HH.MM.SS
#
#	Functions
#
	backup_dir() { # LABEL
	# Creates a tarball using with leading data-time and closing 'LABEL'
	# For label, should provide either 'beginn' or 'end'
		[ -z "$1" ] && return 1
		pushd "$DIR_BASE"
		tar -acf "$DIR_TRGT/${DIR_BKUP##*/}-$NOW-$1.tar.gz" "$DIR_BKUP"
		popd
	}
#
#	Action
#
	backup_dir beginn
	ardour4
	backup_dir end

Make it executable:
Code:
chmod +x $HOME/bin/myardour4

Open a terminal window and type:
Code:
myardour4

Hope this helps
# 7  
Old 01-24-2016
Hi zorrokan...

Apologies for any typos...

From #5 you say it is manually launched either by the GUI or Command Line at any random time(s) and shut down also at any random time(s).

So you need to detect when the program has actually started running to automatically do a backup to '/full/path/to/some/folder1' and when it is exited/quitted to save another backup to '/full/path/to/some/folder2'?

So you wish this script to run 24/7 in the background?

Do you want the copy all files into '.....folder1' and similarly copy all other files into '.....folder2' or do _zipped_ versions of the same?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

The application was unable to start correctly(0xc0150002).

Dear Team, please help me on the issue "The application was unable to start correctly(0xc0150002).click ok to close the application" Have created the build using installshield 2012. dll was generated from VS2008. Used 3rd party libraries.Included all the libraries,dll. This was the first tme... (1 Reply)
Discussion started by: SA_Palani
1 Replies

2. UNIX for Dummies Questions & Answers

Shell Scripting Stop/Start Application

I did a search of these forums but couldnt find a suitable resolution. I am attempting to script a stop and start of an application on AIX. Such as: However it has authentication where username and password prompts will appear after running the above command requiring input from a... (2 Replies)
Discussion started by: Soupy
2 Replies

3. Windows & DOS: Issues & Discussions

Start windows application (.bat) from Unix

How can I start an application sitting on a windows machine (XP) from Unix shell script (AIX server) ? (6 Replies)
Discussion started by: pkan
6 Replies

4. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

5. UNIX for Dummies Questions & Answers

How to start application and keep script running

What I'm looking for is best explained with a little example. #!/bin/bash gedit echo "I need this message to appear while gedit is still running, but it appears only then when I close gedit." Of course most of the times you want the script to wait, but in this case I want to start a new... (5 Replies)
Discussion started by: MrZehl
5 Replies

6. Programming

TCP trashing data on application close

I am using c to send data to a socket with the following commands: socket = socket(AF_INET, SOCK_STREAM, ptrp->p_proto); ioctl(socket, FIONBIO, (char *)&on); connect(socket) send(socket,data) shutdown(socket, SHUT_WR); recv(socket) //ready last of data waiting on the port //note this is... (3 Replies)
Discussion started by: metrix
3 Replies

7. Shell Programming and Scripting

Start and stop of an application thru shell scripts.

Hi, I just learnt the shell scripting and got working on that right now. I have one problem. Here i am having a java application that needs to be start and stop using two shell scripts, i.e., starting the java application using one shell script and stopping the application using another... (1 Reply)
Discussion started by: sadha
1 Replies

8. Linux

where to put an application if i want to start it on start up

hi i want to know the way by which i put any file somewhere and it get s started when the system restarts or bots i mean whenever my system starts that application must also start thanks (3 Replies)
Discussion started by: shukla_chanchal
3 Replies

9. UNIX for Dummies Questions & Answers

how do i auto start application upon startup?

sorry, i'm a newbie to unix... but how do i or rather where do i write scripts that auto start my application e.g. Informix? in Windows it would be services but in UNIX where can i auto start my informix program? To run informix i just type "oninit". And do i have to login to any user before... (2 Replies)
Discussion started by: doofie
2 Replies

10. UNIX for Advanced & Expert Users

Start application after Oracle has started

Who can tell me how I can see to it that a application doesn't try to start it's processes untill Oracle has completely started. Thanx. (3 Replies)
Discussion started by: Piet
3 Replies
Login or Register to Ask a Question