Solved

tar only files that have a certain number in filename.

Posted on 2014-04-20
5
523 Views
Last Modified: 2014-04-23
Hi all.

I'm not a pro yet with command line so i wanted to ask here incase i mess anything up with my centOS server.

I have a folder on my server that plesk puts its website backups in:

/var/lib/psa/dumps/

Within this folder it has loads of random backups and configs files along with a folder named domains that holds all the individual backups for each domain that plesk is hosting.

A backup is done weekly and the dumps just keeps storing more clutter.

every month i would like to download only the files that match the latest backup. (for safe keeping)

When a full server backup is done i can see its unique number inside the plesk dashboard. This number is also appended to the end of each backups file name.

So my thoughts are to copy all the files found in dumps/ and its subdirectories that have the unique number in the file names over to a .tar archive.

Then i can simply download the tar each time i need the latest backup.
I have searched online and found this command:
find ./ -type f -name "*.txt" -exec tar uvf myarchives.tar {} +

My unique number for the last backup is 1404190251
This is how all the files names are formed:
weeklyBackup_admin_angela_1_1404190251.tgz
weeklyBackup_angela-wright.com_apache-files_1404190251.tgz
weeklyBackup_angela-wright.com_info_1404190251.xml
and so on...

how can i modify the command so that it grabs these files with the number in the center of the filename as they all have different file extensions. Do i just add a * at the front and back like this?:
 "*1404190251*"

and will this command do a copy or will it remove the files after adding to the tar archive?
i would like to keep the old files in place if possible.

Thanks.
0
Comment
Question by:helpchrisplz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 14

Assisted Solution

by:brendanmeyer
brendanmeyer earned 250 total points
ID: 40011830
adding the * should work

find ./ -type f -name "*1404190251*" -exec tar uvf myarchives.tar {} +
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 40011834
Hi brendanmeyer

where would the .tar file be created? the current folder?
0
 
LVL 14

Expert Comment

by:brendanmeyer
ID: 40011900
yeah the current folder
0
 
LVL 38

Accepted Solution

by:
Gerwin Jansen, EE MVE earned 250 total points
ID: 40012275
>> and will this command do a copy or will it remove the files after adding to the tar archive?
The command will update an (existing) tar file. It will not remove the existing .tgz and xml files.

I suggest you create a new tar file instead, containing the same backup ID as your files have, you can then FTP/backup that file and after checking remove the files that were backed up. Otherwise you will keep on having lots and lots of files in the dumps folder.

I'd change the tar command like this:
find /var/lib/psa/dumps/ -type f -name "*1404190251*" -exec tar cvf 1404190251.tar {} +

Open in new window


If you want to see what the tar command would do without actually creating the tar file, add an 'echo' command, like this:
find /var/lib/psa/dumps/ -type f -name "*1404190251*" -exec echo tar cvf 1404190251.tar {} +

Open in new window


And if you don't want to type the name twice:
echo "Enter archive name: " ; read aname ; find /var/lib/psa/dumps/ -type f -name "*$aname*" -exec tar cvf "$aname".tar {} +

Open in new window

0
 
LVL 1

Author Closing Comment

by:helpchrisplz
ID: 40018141
ty
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
number in printf 13 42
LogmeIn using Linux Ubuntu 16.04 6 116
Can we or good to install Ap Struts patches even if we don't run Ap Struts 7 57
$_SERVER Variable question 31 56
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

733 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