Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

what this cleanit functino does?

Posted on 2013-01-08
12
Medium Priority
?
204 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 21

Assisted Solution

by:netcmh
netcmh earned 1004 total points
ID: 38757301
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
ID: 38757303
then what does this part mean: sed '1 d' ?
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 332 total points
ID: 38757334
It deletes the first line
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 664 total points
ID: 38757338
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
ID: 38757389
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 664 total points
ID: 38757580
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
 
LVL 21

Accepted Solution

by:
netcmh earned 1004 total points
ID: 38759583
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
ID: 38759810
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 21

Assisted Solution

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

Author Comment

by:Jason Yu
ID: 38779657
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
ID: 38779659
Good service.
0
 
LVL 21

Expert Comment

by:netcmh
ID: 38783166
Thanks for the grade. Good luck.
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…
Suggested Courses

564 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