@Test
  public void testBackUpAndRestorePartition() throws Exception {

    // Insert few rows
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(1,1,'p1'),(2,2,'p1'),(3,3,'p1')");
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(4,4,'p1')");
    runStatementOnDriver("insert into " + Table.ACIDTBLPART + " partition(p) values(1,2,'p2'),(2,3,'p2'),(3,4,'p2')");

    List<String> r = runStatementOnDriver("select a, b from " + Table.ACIDTBLPART + " order by a, b");
    int[][] expected = { { 1, 1 }, { 1, 2 }, { 2, 2 }, { 2, 3 }, { 3, 3 }, { 3, 4 }, { 4, 4 } };
    Assert.assertEquals(stringifyValues(expected), r);

    // copy files on fs
    FileSystem fs = FileSystem.get(hiveConf);
    fs.mkdirs(new Path(getWarehouseDir(), "mybackup"));
    FileUtil.copy(fs, new Path(getWarehouseDir() + "/" + Table.ACIDTBLPART.toString().toLowerCase() + "/p=p1"), fs,
        new Path(getWarehouseDir(), "mybackup"), true, hiveConf);

    // call msk repair to remove partition p1
    runStatementOnDriver("msck repair table " + Table.ACIDTBLPART + " SYNC PARTITIONS");

    r = runStatementOnDriver("select a, b from " + Table.ACIDTBLPART + " order by a, b");
    int[][] expected2 = { { 1, 2 }, { 2, 3 }, { 3, 4 }};
    Assert.assertEquals(stringifyValues(expected2), r);

    // copy the data back
    FileUtil.copy(fs, new Path(getWarehouseDir() + "/" + "mybackup" + "/p=p1"), fs,
        new Path(getWarehouseDir(), Table.ACIDTBLPART.toString().toLowerCase()), true, hiveConf);

    // call msk repair to add the partition back
    runStatementOnDriver("msck repair table " + Table.ACIDTBLPART);

    r = runStatementOnDriver("select a, b from " + Table.ACIDTBLPART + " order by a, b");
    Assert.assertEquals(stringifyValues(expected), r);
  }
Delete one partition from a table, drop the partition from the HMS, then restore the partition
and repair the table.
@throws Exception ex
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestMSCKRepairOnAcid.java