aspose file tools*
The moose likes Java in General and the fly likes Java File Backup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java File Backup" Watch "Java File Backup" New topic
Author

Java File Backup

Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Hi,

I am creating a file backup program in java. I tried back up using sockets but it was too slow with increase in number of files, so I tried using mail then again it dumps files in mail. Is there a more faster and effective way to implement file backup?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
It sounds like the files would end up on a different machine; is that correct? If so, I might use compression and archiving on the client computer, and then a file transfer tool like FTP to upload the file to the target machine.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

Yes the files will back up on another computer. Sorry I forgot about compressing. Can we build a file transfer tool in Java? I don't want to use other tool. I want to learn and build one. Can you show me where to start?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
You can start by using ZIP for compression and archiving. Everything you need for that is in the java.util.zip package. If you want to use different archiving or compression algorithms, check out the Apache Commons Compress library. For the client side of FTP file upload you can use the Apache Commons Net library.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

I will surely try it and get back to you. I need to transfer files within a LAN only but multiple clients. So is there any other way?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
There are any number of ways to transfer files. Which one is best depends on the circumstances, like the full set of requirements (about which we know nothing at present). If you need a more differentiated answer, start by explaining in detail how FTP does not fit your requirements, so that we can guess at what might be a better solution.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

FTP will fit my needs, I am just exploring others options. Moreover I need to write my own FTP server in my Server application, if i decide to use FTP. The process is as given below:

Step 1: Server sends a command to all clients at a specific time to backup certain type of files (say doc,txt, etc.)

Step 2: All the clients connected to the server will send those files. If a particular client isn't connected at the time, it should send the files once it is selected.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
No disrespect, but writing your own FTP server is no good. It's also unnecessary, as free FTP servers are a dime a dozen. If you want something written in Java, Mina can be run standalone or embedded.

Step 1 looks like a needless complication to me. Clients should backup whatever they are configured to back up whenever they are configured to do so. What purpose would a server command have? Are there requirements that you haven't told us about? (Please don't say "these are my requirements", because that wouldn't help. I'm asking for the reasons.)
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

Thanks for the feedback and sorry for the late reply. Step 1 is the requirement. At a predefined time say 5:00 pm, the server should back up the files with predefined extensions.

I tried Mina and was successful in connecting to the server but I need to download the files sent to the system running the server. I will post this as a new question.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

If this has to be done at a pre-defined time, why does the server have to send out the command? Why can't each client know to do the job at 5p? This is exactly what cron is built to do. You simply schedule a cron job for 5p, and the client will fire off the job. No command from the server is necessary.

Unless the specific time of the job matters, and it will change often, that requirement just seems silly.

And considering you state that if a client is down, it should send the files when it is up, then the timing doesn't sound like it matters all that much.

You could even schedule a cron to run every 15 minutes. The first thing the job does is ask itself "When did I last send my backups?" - and if it's recently, it says "OK, I don't need to send anything now" and shuts down. Otherwise it sends everything, logs when it sent it, and you're golden.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

fred,

5 pm is just an example. When the person handling the server likes to change the time, he can change it. I am doing this on Windows platform, is a cron job possible here?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42926
    
  68
On Windows it's called Task Scheduler.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

Ulf,

Thanks for the feedback. I don't have problem in triggering, I used Timer task for it.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11498
    
  16

A problem you are going to have with a server sending out a request will be when a client is down. That box will not get the request. When it comes back up, how will it know that a request was sent?

and of course, the problem with using cron or scheduled tasks is that it is hard to change every single one to a new time on-the-fly.

I'd still probably lean towards the cron/task idea running every hour (or whatever). If the exact time of the back-ups matter, then the server could maintain a list of when each client last updated and when they are desired. When the client job runs, it asks the server "do you want my files now?" and then proceeds accordingly.
Partheban Udayakumar
Ranch Hand

Joined: Jul 04, 2013
Posts: 267

fred

That's a valid point. I thought of that already. Since I was using sockets for file backup, I programmed the Timer task from server and at the specific time, the server will initiate a three way handshake. First the server will check for connection availability, if connection exists an ack will be returned and then the file backup command is sent from the server. Now I am trying to implement file backup with FTP as Ulf suggested in his post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java File Backup