Solved

what this cleanit functino does?

Posted on 2013-01-08
12
182 Views
Last Modified: 2013-01-16
Dear all:

when i am reading a backup script, i found this line is hard to understand, could you explain it to me a bit? Thank you in advance.


# The number of days to delete during the cleanIt function
delDays=+5

cleanIt () {

# This script clean the old data off of the drive. The var $delDays tells the script how many days to delete.
sleep 20
rm -rf $(find /u1/backupdisk/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep backup)
}


I don't understand the parameters behind rm -rf.

"rm -rf $(find /u1/backupdisk/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep backup)"

Thanks.
0
Comment
Question by:Jason Yu
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 20

Assisted Solution

by:netcmh
netcmh earned 251 total points
Comment Utility
That command will delete files inside /u1/backupdisk directory older than 5 days with the word backup in the name.
0
 

Author Comment

by:Jason Yu
Comment Utility
then what does this part mean: sed '1 d' ?
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 83 total points
Comment Utility
It deletes the first line
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 166 total points
Comment Utility
sed 1d removes the first line of output from the find command, so it effectively leaves one backup file in the directory.

It is better written as:
find /u1/backupdisk/ -maxdepth 1 -name "*backup*" -mtime $delDays|xargs rm -f

Open in new window

0
 

Author Comment

by:Jason Yu
Comment Utility
If I want to delete the old archives in this folder /u2/backup/luna

as listed:

[root@titan luna]# ls -l
total 268723836
-rw-r--r--  1 nfsnobody nfsnobody 31380309423 Dec  3 22:51 luna.minkagroup.net20121203.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31386717967 Dec  4 22:45 luna.minkagroup.net20121204.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31392048069 Dec  5 22:43 luna.minkagroup.net20121205.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31397210055 Dec  6 22:45 luna.minkagroup.net20121206.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31401869675 Dec  7 22:54 luna.minkagroup.net20121207.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31591944161 Dec 10 22:50 luna.minkagroup.net20121210.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 31597450665 Dec 11 22:52 luna.minkagroup.net20121211.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody 30313918464 Dec 12 22:39 luna.minkagroup.net20121212.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody       98304 Dec 13 20:25 luna.minkagroup.net20121213.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 14 20:24 luna.minkagroup.net20121214.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 17 20:25 luna.minkagroup.net20121217.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 18 20:23 luna.minkagroup.net20121218.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 19 20:21 luna.minkagroup.net20121219.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 20 20:24 luna.minkagroup.net20121220.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 21 20:25 luna.minkagroup.net20121221.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 24 20:26 luna.minkagroup.net20121224.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 25 20:24 luna.minkagroup.net20121225.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 26 20:24 luna.minkagroup.net20121226.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 27 20:23 luna.minkagroup.net20121227.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 28 20:23 luna.minkagroup.net20121228.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Dec 31 20:27 luna.minkagroup.net20121231.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  1 20:25 luna.minkagroup.net20130101.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  2 20:24 luna.minkagroup.net20130102.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  3 20:23 luna.minkagroup.net20130103.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  4 20:22 luna.minkagroup.net20130104.tar.gz
-rw-r--r--  1 nfsnobody nfsnobody           0 Jan  7 20:24 luna.minkagroup.net20130107.tar.gz
-rw-rwxr--+ 1 root      root      24711580946 Sep 13 19:21 lunaPre5.2.4Patch.tar.bz
drwxrwx---+ 2 nfsnobody nfsnobody        4096 Oct 12 12:28 oracle
[root@titan luna]# pwd
/u2/backup/luna
[root@titan luna]#


Is my script better workable?

# old scripts from last time
# rm -rf $(find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net)
# New script from Jason
find /u2/backup/luna -maxdepth 1 -name "*luna.minkagroup*" -mtime $delDays|xargs rm -f
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 166 total points
Comment Utility
My mistake, I meant to write
find /u1/backupdisk/ -maxdepth 1 -name "*backup*" -mtime $delDays|sed 1d|xargs rm -f

Open in new window

0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 20

Accepted Solution

by:
netcmh earned 251 total points
Comment Utility
You can always test the script without the delete function

so remove the rm -rf and the () brackets and see if the output matches the resultset you want deleted and then add them back in.

So, try

find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net

then add in the rm -rf ()

rm -rf (find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net)
0
 

Author Comment

by:Jason Yu
Comment Utility
when i run this command, it doesn't give me any result:

find /u1/nfsbackup -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net



/u1/nfsbackup is a mounted partition from another server, i use number 10 to replace $delDays globe var.

Very interesting thing is, if I list the directory /u1/nfsbackup, it doesn't show anything either.

I am guessing this folder was not mounted. Am I right?

[root@luna nfsbackup]# cat /etc/fstab
/dev/OS/root            /                       ext3    defaults        1 1
/dev/OS/tmp             /tmp                    ext3    defaults        1 2
/dev/OS/usr             /usr                    ext3    defaults        1 2
/dev/OS/var             /var                    ext3    defaults        1 2
/dev/GIS/LogVol00       /u1                     ext3    defaults        1 2
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   size=3g         0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda6         swap                    swap    defaults        0 0
titanbk:/u2/backup/luna /u1/nfsbackup           nfs     _netdev,noauto 0 0
titanbk:/u2/backup/luna/oracle /u1/oracle/backup nfs    _netdev,noauto 0 0
[root@luna nfsbackup]# find /u2/backup/luna/ -maxdepth 1 -mtime $delDays|sed '1 d' |grep luna.minkagroup.net
find: missing argument to `-mtime'
[root@luna nfsbackup]# find /u2/backup/luna/ -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net
find: /u2/backup: No such file or directory
[root@luna nfsbackup]# find /u1/nfsbackup -maxdepth 1 -mtime 10|sed '1 d' |grep luna.minkagroup.net
[root@luna nfsbackup]# ls /u1/nfsbackup
[root@luna nfsbackup]#
0
 
LVL 20

Assisted Solution

by:netcmh
netcmh earned 251 total points
Comment Utility
That would explain why you can't see any results for the command. Check the mount table.
0
 

Author Comment

by:Jason Yu
Comment Utility
yes, that partition is from a network share, it was not mounted successfully.

This case was resolved, thank you very much.
0
 

Author Closing Comment

by:Jason Yu
Comment Utility
Good service.
0
 
LVL 20

Expert Comment

by:netcmh
Comment Utility
Thanks for the grade. Good luck.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now