Tuesday, May 12, 2009

How to backup of your blogger blog

There are many ways to take your blog backup. Even some tools are also available in market. But here I explain two ways:

1. Write one simple java program and take many blog backup together with timestamp.
2. Use Export and Import facility of blogger

1. Write one simple java code (BlogBackup.java)


import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BlogBackup {
public static String repo = "E:\\Blog_BACKUP\\";
public static String ext = ".xml";
public static String url1 = "http://your_blogName _1.blogspot.com/feeds/posts/default?max-results=1000";
public static String url2 = "http://your_blogName _2.blogspot.com/feeds/posts/default?max-results=1000";
public static String url3 = "http://your_blogName _3.blogspot.com/feeds/posts/default?max-results=1000";

public static void main(String[] args) {
takeBackup();
}
public static void takeBackup(){
String folderName = createFolder();
String[] url = {url1,url2,url3};
try {
for(int i=0;iString fileName = folderName+"\\"+getFileName(url[i]);
doDownload(url[i],fileName);
System.out.println("Completed :: "+fileName);
}
} catch (IOException e) {e.printStackTrace();}
}
public static String getFileName(String url){
String fileName = url.substring(url.indexOf("//")+2,url.indexOf("."));
Format formatter = new SimpleDateFormat("MMM-dd-yyyy-HH-mm");
String now = formatter.format(new Date());
return fileName+"_"+now+ext;
}
public static String createFolder(){
Format formatter = new SimpleDateFormat("MMM-dd-yyyy");
String folderName = repo + formatter.format(new Date());
System.out.println("Folder Name :: "+folderName);
File file = new File(folderName);
if(!file.exists()){
file.mkdir();
}
return folderName;
}
public static void doDownload(String blogURL, String fileName) throws IOException {
String charset = "utf-8";
URL url = new URL(blogURL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
InputStream inputStream = null;
inputStream = url.openStream();
StringBuffer s = new StringBuffer();
if(charset==null"".equals(charset)){
charset="utf-8"; }
String rLine = null;
BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream,charset));
PrintWriter printWriter = null;
FileOutputStream fo = new FileOutputStream(fileName);
OutputStreamWriter writer = new OutputStreamWriter(fo, "utf-8");
printWriter = new PrintWriter(writer);
while ( (rLine = bReader.readLine()) != null) {
String line = rLine;
int str_len = line.length();
if (str_len > 0) {
s.append(line);
printWriter.println(line);
printWriter.flush();
}
line = null;
}
inputStream.close();
printWriter.close();
}
}

You can change the repository folder name, I used here "E:\\Blog_BACKUP\\";
Whenever you will run this java code, it will create folder as running date and inside that folder your all blog backup will come with timestamp.

Please share your comments with me ........... :)

2. Another way
Step1 : Login to your blog (http://www.blogger.com)
Step2: Go to Setting tab
Step3: You will get Blog Tools (Upper left side)
Step4: Right side option are there like Import blogs, Export blogs, Delete blogs.

4 comments:

  1. How about the reader's comments? It's will backup together with all entries using way number 1? how with way number 2?

    ReplyDelete
  2. Hi Irtiyah, If you will use second method then you can take also your all comments with blog content. Just try it, its work fine. I posted this atricle only after myself used.

    Thanks,

    Binod Suman
    http://binodsuman.blogspot.com

    ReplyDelete
  3. I also checked, it worked fine. Thanks.

    Akash USA

    ReplyDelete
  4. by blog take down how can i retrieve backup file

    ReplyDelete

Please put your feedback or your any question related to this blog. Thanks.