Sponsored Content
Top Forums Shell Programming and Scripting Find all .htaccess files and make a backup copy in respective directories Post 302525963 by boxx on Monday 30th of May 2011 12:03:52 AM
Old 05-30-2011
I appreciate the responses, but I don't think that's quite what I'm looking for. Adding a date to the file... really doesn't get me anywhere, nor does a manual file by file copy to replace. Let me try to clarify...

I have approx 3,000 .htaccess files I am planning on targeting with a script to update them all at once removing a specified RE.

/dir1/.htaccess
/dir1/sub1/.htaccess
/dir1/sub2/.htaccess
/dir1/sub2/nest1/.htaccess
/dir2/.htaccess
/dir2/sub1/.htaccess
/dir2/sub2/.htaccess
/dir2/sub2/nest1/.htaccess
etc...

I've used:

Code:
find <start_directory> -iname ".htaccess" -exec cp -v {} {}_bak \;

To create a backup of each .htaccess to sit along side the original in every directory, so it now sits like this:

/dir1/.htaccess
/dir1/.htaccess_bak
/dir1/sub1/.htaccess
/dir1/sub1/.htaccess_bak
/dir1/sub2/.htaccess
/dir1/sub2/.htaccess_bak
/dir1/sub2/nest1/.htaccess
/dir1/sub2/nest1/.htaccess_bak
/dir2/.htaccess
/dir2/.htaccess_bak
/dir2/sub1/.htaccess
/dir2/sub1/.htaccess_bak
/dir2/sub2/.htaccess
/dir2/sub2/.htaccess_bak
/dir2/sub2/nest1/.htaccess
/dir2/sub2/nest1/.htaccess_bak
etc...

Now I'm going to run a script through all the original .htaccess files using find and sed -i to remove a selection of unwanted rewrite rules, while leaving the remaining rules in place. I'm pretty sure it is going to go as planned, but I want to be on the safe side and have backups in place, and a method to restore the original .htaccess files with the backups that reside along side them, if something goes wrong.

I need a method to find all .htaccess_bak files and rename them as .htaccess to overwrite the .htaccess files that are sitting along side them.

So in other words:

/dir1/.htaccess_bak is renamed to /dir1/.htaccess ... overwriting and replacing the .htaccess that is in place.
/dir1/sub1/.htaccess_bak is renamed to /dir1/sub1/.htaccess ... overwriting and replacing the .htaccess that is in place.
/dir1/sub2/.htaccess_bak is renamed to /dir1/sub2/.htaccess ... overwriting and replacing the .htaccess that is in place.

leaving a file structure like the original.

/dir1/.htacces
/dir1/sub1/.htaccess
/dir1/sub2/.htaccess
etc

But I need to do this for 3000 files at one time, not a cp or mv or rename... one by one by one manually..

I think this can be accomplished much along the lines of what I'm already using to create the backups. something like...

Code:
find <start_dir> -iname ".htaccess_bak" -exec rename {} {.htaccess} \;

I'm pretty sure the syntax there isn't correct, but I think it gives you an idea of what I'm trying to accomplish.

Any other thoughts or tips?

Thanks much!
BoxX
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

copy multiple files in different directories

I have a report file that is generated every day by a scheduled process. Each day the file is written to a directory named .../blah_blah/Y07/MM-DD-YY/reportmmddyy.tab I want to copy all of this reports to a separate directory without having to do it one by one. However, if I try cp... (3 Replies)
Discussion started by: ken2834
3 Replies

2. Shell Programming and Scripting

Make python script ignore .htaccess

I just wrote a tiny script with the help of ghostdog74 to search all my files for special content phrases. After a few modifications I now made it work, but one problem is left. The files are located in public_html folder, so there might also be .htaccess files. So I ignored scanning of that... (4 Replies)
Discussion started by: medic
4 Replies

3. UNIX for Dummies Questions & Answers

how can i copy those files into other directories have the same name

how can i copy those files into other directories have the same name but different in the end i have files in directory called test: 10_10_asdadfsdfad.txt 10_10_11_asdawqefwkjasd.txt 10_10_11_12_asdafjjhoqwd.txt i want to put them in exist directory thart i have on my system i have... (1 Reply)
Discussion started by: t17
1 Replies

4. Shell Programming and Scripting

Replace several numbers with respective tag and make a single file

Dear All, I have a final output files as 736645|0| 13879|1| 495563|10| 127933|14| 4975|16| 49038|6| 53560|7| 135115|8| 178857|9| Now I want to replace second column with respective tag as per the value (4 Replies)
Discussion started by: jojo123
4 Replies

5. Shell Programming and Scripting

Copy respective path next to last column with awk

Hi to all, I have the short print out sample of the DOS command "dir S/" as showed below. Directory of C:\Program Files\Winamp\Skins\Bento\window 02/12/2010 11:35 p.m. <DIR> . 02/12/2010 11:35 p.m. <DIR> .. 11/12/2009 10:31 a.m. 13,556... (3 Replies)
Discussion started by: cgkmal
3 Replies

6. Shell Programming and Scripting

Copy directories in make file

LD:=C:/WindRiver/diab/5.9.3.0/WIN32/bin/dld.exe CFILES:=$(wildcard *.c) OBJFILES:=$(subst .c,.o, $(CFILES)) OBJ_PATH:=$(PRJ_PATH)/out/ ADDOBJFILES := $(addprefix $(OBJ_PATH),$(OBJFILES)) FILES:=C:/EB/tresos/workspace/Test_Spi/output/src copyfiles: cp ... (3 Replies)
Discussion started by: ushacy
3 Replies

7. AIX

How to backup a directory (sub-directories/files) files from one server on to other ?

Hello, Server A: /directory1/ Server B: /Backups/ i wanted to backup contents of /directory1 from "server A" on to "Server B" every 1 hour. If there is any change in (only new/differences) contents on serverA (directory1/) supposed to be backeup on next run. I did used rsync command to... (5 Replies)
Discussion started by: System Admin 77
5 Replies

8. Shell Programming and Scripting

Copy files in respective directories

Hi Guys, I need to copy the files to respective directories based on name of the file. My script is something like below con=$1 for file in `cat $con` do file_tmp=$(ls -t1 $path| grep -i $file | head -n 1) echo $file_tmp if then cp $path$file_tmp $DIR/ap if then... (16 Replies)
Discussion started by: Master_Mind
16 Replies

9. Shell Programming and Scripting

Find and Copy Directories ONLY

I am trying to copy only the date specific folders/directories using the following command. However, the following copy command is also copying files from the root folder (OriginalFolder). find /OriginalFolder/ -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \;... (2 Replies)
Discussion started by: apacheLinux
2 Replies
BBACKUPD-CONFIG(8)						    Box Backup							BBACKUPD-CONFIG(8)

NAME
bbackupd-config - Box Backup client daemon configuration file generator SYNOPSIS
bbackupd-config config-dir backup-mode account-num server-hostname working-dir backup-dir [backup-dir ...] DESCRIPTION
The bbackupd-config script creates configuration files and client certificates. It takes at least six parameters: config-dir Configuration directory. Usually /etc/box. backup-mode Either lazy or snapshot. account-num The client account number. This is set by the bbstored administrator. server-hostname The hostname or IP address of the bbstored server. working-dir A directory to keep temporary state files. This is usually something like /var/bbackupd. This can be changed in bbackupd.conf later on if required. backup-dir A space-separated list of directories to be backed up. Note that this does not traverse mount points. FILES
/etc/box/bbackupd.conf /etc/box/bbackupd/NotifySysAdmin.sh SEE ALSO
bbackupd.conf(5), bbackupd(8), bbackupctl(8) AUTHORS
Ben Summers Per Thomsen James O'Gorman Box Backup 0.11 10/28/2011 BBACKUPD-CONFIG(8)
All times are GMT -4. The time now is 04:38 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy