Sponsored Content
Full Discussion: Find, backup and delete.
Top Forums Shell Programming and Scripting Find, backup and delete. Post 302893583 by leo_ultra_leo on Thursday 20th of March 2014 04:28:46 AM
Old 03-20-2014
Hey guys, I have fixed and tested it like this..

Code:
#!/bin/bash

# Environment Variables
FINDPATH=/home/ftpcdr/cdr/192.168.3.91
BACKPATH=/home/ftpcdr/backup

# Change into CDRs directory, find the CDRs which created before 30 days and create a list for them in list.txt

cd $FINDPATH && find -type d -mtime +30 | grep -o '[0-9]*' | sort > $BACKPATH/list.txt

# Environment Variables

FIRST=$(cat $BACKPATH/list.txt | grep "[0-9]" |  head -n 1)
LAST=$(cat $BACKPATH/list.txt | grep "[0-9]" | tail -n 1)
LISTFILE=/home/ftpcdr/backup/list.txt

# If we dont have a valid CDRs within this time, then exit the script Else, backup (and compress)
# these files into our backup directory and name it as of the period of CDR creation.

if  [ ! -s "$LISTFILE" ]
then
echo "No data to backup!" && exit
else
cd $FINDPATH && tar -czf $BACKPATH/$FIRST\_$LAST.tar.gz `cat $BACKPATH/list.txt`
fi

#If this operation completed successfully, then delete the original CDRs. Script job has done!

if [ "$?" = "0" ]; then
cd $FINDPATH && find -type d -mtime +30 -delete && echo "CDRs have been successfully archived from $FIRST to $LAST on $BACKPATH"
else
echo "CDRs BACKUP ERROR!"
fi

#End of script, EOT

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find directory and create backup

What I'm attempting to do is create a script that will do a search for directories that meet the following criteria: find . -name "config" -type d this comes back with: ./dir1/anotherDir/test_dir/config ./dir1/anotherDir/test_dira/config ./dir2/test/test_dir/config The results could... (4 Replies)
Discussion started by: cbo0485
4 Replies

2. Shell Programming and Scripting

Mp3 backup using find, mkisofs

Hi. I want to create a Linux script to find all local mp3 files, create an ISO image. Later I will attempt to use growisofs Something like this: find ~ -name "*.mp3" | xargs mkisofs -o musicbackup tried variations on this but no luck. (4 Replies)
Discussion started by: lancest
4 Replies

3. Shell Programming and Scripting

Find and delete everything else...

Ok, new user, relatively new to scripting and need to move to the next stage with awk or sed or both. I have been using them both at a basic level in my script. I want to find a line, no problem, but then I want to delete everything on that line except for the word I am looking for AND the... (4 Replies)
Discussion started by: derekphl
4 Replies

4. Shell Programming and Scripting

Find all .htaccess files and make a backup copy in respective directories

Hey guys, I need to know how to locate all .htaccess files on the server and make a backup of them in the folder they reside before I run a script to modify all of them. So basically taking dir1/.htaccess and copying it as dir1/.htaccess_bk dir2/.htaccess copying as dir2/.htaccess_bk... (5 Replies)
Discussion started by: boxx
5 Replies

5. Shell Programming and Scripting

scripts to Initialise,backup,restore,delete and empty

you are to write scripts for a customer that would require a system enable the backing up of files and directories. The script should (these names should be used): 1. INITIALISE: Initialise the directory for the backup(called backup and should be in the home directory) and any other... (1 Reply)
Discussion started by: babby01
1 Replies

6. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

7. Shell Programming and Scripting

Script - Mysql backup and delete

Hello I have a production mysql server and archive server, unfortunitly its not possible to setup repliacation between the two, the reason is that the archive server is using some fancy storage engine which doesn't allow mysql replication. I'm trying to write a script using perl that does... (1 Reply)
Discussion started by: amlife
1 Replies

8. Shell Programming and Scripting

Look for, backup and delete symlinks

Hi, My first post here: Was looking if someone can help enhancing my code. I am limited to sh or ash shell (android / busybox) I made a script to look for busybox symlinks, backup them and delete them I have these questions about the below code: - busybox tar do not has the options... (2 Replies)
Discussion started by: Phil3759
2 Replies

9. Red Hat

RHEL 7: Backup Space and Delete is not working in console

Hi All, During my virtual machine power on i have rc3.d script to accept user inputs like IP address. This script gets executed during first time boot up. It was working fine till my VM is using RHEL6.5. Now we migrated to RHEL 7 environment. While accepting the user inputs in console, I... (4 Replies)
Discussion started by: kalpeer
4 Replies

10. UNIX for Advanced & Expert Users

AIX find duplicate backup files

I would like find and delete old backup files in aix. How would I go about doing this? For example: server1_1-20-2020 server1_1-21-2020 server1_1-22-2020 server1_1-23-2020 server2_1-20-2020 server2_1-21-2020 server2_1-22-2020 server2_1-23-2020 How would I go about finding and... (3 Replies)
Discussion started by: cokedude
3 Replies
All times are GMT -4. The time now is 02:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy