[Linux] combined with awk to delete data before the specified date in HDFs

Source: Internet
Author: User
Tags hadoop fs

Business Background

Convention five days ago HDFs data is outdated version data, write a script to automatically delete outdated version data

$ Hadoop FS-ls/user/pms/workspace/ouyangyewei/DataFound9Itemsdrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- onDrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- GenevaDrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,-GenevaDrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,-GenevaDrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- toDrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- .Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- -Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- ,Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- the
Script Implementation
#--------------------- ------------------------------------ #  # Delete history version (five days ago for expiration Version data)  #  #------------------------------------ --------------------- old_version=$ ( Hadoop fs-ls/user/pms/workspace/ Ouyangyewei/data | awk  begin{five_days_ago=strftime ("%F", Systime () -5*24*3600)} {split ($8,arr, "/"); if (arr [7]<five_days_ago) {printf "%s\n", $8}} ' ) arr= (${ Old_version///}) for  version in  ${ arr[@]} do  hadoop fs-rmr  $version  done  

After execution

$ Hadoop FS-ls/user/pms/workspace/ouyangyewei/DataFound4Itemsdrwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- .Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- -Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- ,Drwxr-XR- x   -PMS PMS0  -- ,- One  -:Geneva/user/pms/workspace/ouyangyewei/Data/ -- ,- the

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[Linux] combined with awk to delete data before the specified date in HDFs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.