Solved

what this cleanit functino does?

Posted on 2013-01-08
12
189 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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
 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS ELB 5 95
Remote desktop Ubuntu from Windows 10 5 96
awk file 6 79
trouble on installing syslog-ng on CentOS 7 7 57
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…
Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

830 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