Solved

what this cleanit functino does?

Posted on 2013-01-08
12
184 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
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 83 total points
ID: 38757334
It deletes the first line
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 166 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 166 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 20

Accepted Solution

by:
netcmh earned 251 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 20

Assisted Solution

by:netcmh
netcmh earned 251 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 20

Expert Comment

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

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to copy from computer to usb drive 7 102
CentOS 7 Installation 7 58
Reset Root Password on CentOS 6 4 43
How code a 301 redirect for folder files -> 1 file 2 13
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
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…

919 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

13 Experts available now in Live!

Get 1:1 Help Now