Note that there are some explanatory texts on larger screens.

plurals
  1. POBash copying specific files
    primarykey
    data
    text
    <p>How can I get tar/cp to copy only files that dont end in .jar and only in root and /plugins directories?</p> <p>So, I'm making a Minecraft server backup script. One of the options I wish to have is a backup of configuration files only. Here's the scenario:</p> <ol> <li>There are many folders with massive amounts of data in.</li> <li>Configuration files mainly use the following extensions, but some may use a different one: <ul> <li>.yml</li> <li>.json</li> <li>.properties</li> <li>.loc</li> <li>.dat</li> <li>.ini</li> <li>.txt</li> </ul></li> <li>Configuration files mainly appear in the /plugins folder</li> <li>There are a few configuration files in the root directory, but none in any others except /plugins</li> <li>The only other files in these two directories are .jar files - to an extent. These do not need to be backed up. That's the job of the currently-working plugins flag.</li> </ol> <p>The code uses a mix of <code>tar</code> and <code>cp</code> depending on which flags the user started the process with. The process is started with a command, then paths are added via a concatenated variable, such as <code>$paths = plugins world_nether mysql/hawk</code> where arguments can be added one at a time.</p> <p>How can I selectively backup these configuration files with <code>tar</code> and <code>cp</code>? Due to the nature of the configuration process, we needn't have the same flags to add into both commands - it can be seperate arguments for either command.</p> <p>Here are the two snippets of code in concern: Configure paths:</p> <pre><code># My first, unsuccessful attempt. if $BKP_CFG; then # Tell user they are backing up config echo " +CONFIG $confType - NOT CURRENTLY WORKING" # Main directory, and everything in plugin directory only # Jars are not allowed to be backed up #paths="$paths --no-recursion * --recursion plugins$suffix --exclude *.jar" fi </code></pre> <p>---More Pro Stuff----</p> <pre><code># Set commands if $ARCHIVE; then command="tar -cpv" if $COMPRESSION; then command=$command"z" fi # Paths starts with a space &lt;/protip&gt; command=$command"C $SERVER_PATH -f $BACKUP_PATH/$bkpName$paths" prep="" else prep="mkdir $BACKUP_PATH/$bkpName" # Make each path an absolute path. Currently, they are all relative for path in $paths; do path=$SERVER_PATH/$path done command="cp -av$paths $BACKUP_PATH/$bkpName" fi </code></pre> <p>I can provide more code/explaination where neccessary.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload