B
B
BlagoYar Silence2021-06-01 23:54:28
linux
BlagoYar Silence, 2021-06-01 23:54:28

How to exclude full path from tar?

Like in this script

#!/bin/bash
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

#date=$(date +%d-%m-%Y_%H-%M-%S)
#mbg="moscow-battle.ru_"
#tar -cjpf /user/backup_srv/sites/$mbg"$date".tar.bz2 --exclude-from=/user/backup_srv/filters/filter-list_sites.txt --absolute-names /var/www/moscow-battle.ru

filter="/user/backup_srv/filters/filter-list_sites.txt"
date=$(date +%d-%m-%Y_%H-%M-%S)
sites="/var/www"
mvsource="/user/backup_srv/sites/sites_$date.tar.bz2"
mvdest="gdrive:/backup_sites/$date.tar.bz2"

tar -cjpf /user/backup_srv/sites/sites_"$date".tar.bz2 --exclude $sites/demo.moscow-battle.ru --exclude $sites/fastdl.moscow-battle.ru --exclude-from=$filter --absolute-names $sites
rclone moveto "$mvsource" "$mvdest"

#find moscow-battle.ru -type f -size -50M -print0 | tar -cjpf /user/back up_srv/sites/$mbg.tar.bz2 --null -T -

Exclude this path?

PS. Tried -C and --directory before $sites, but gives different errors

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sergey, 2021-06-02
kuzmin @sergueik

change the current directory before launch tarand tweak the arguments:

oldpwd=`pwd`
cd $sites ; 

tar -cjf /user/backup_srv/sites/sites_"$date".tar.bz2 --exclude demo.moscow-battle.ru --exclude fastdl.moscow-battle.ru --exclude-from=$filter  .
cd $oldpwd

V
Victor Taran, 2021-06-03
@shambler81

Write what exactly you want to do, not the problem itself, but the action. perhaps there are already ready-made scripts.
here atk exclusions are made.

tar -cvpzf $TMPDIR/$DATEYM/$ELEMENT-$DATE.tar.gz --directory $SITEDIR/$ELEMENT/$WEB --ignore-failed-read --exclude='./bitrix/tmp' --exclude='./bitrix/updates' --exclude='./bitrix/backup/*\.gz*' --exclude='./bitrix/backup/*\.tar*' --exclude='./bitrix/cache' --exclude='./bitrix/managed_cache' --exclude='./bitrix/stack_cache' --exclude='./upload/resize_cache' --exclude='./stats' . >> /dev/nool 2> /var/log/backup_error.log

G
ge, 2021-06-08
@gedev

There are some terrible crutches in the comments to the question :)
The author, apparently you used -C incorrectly . An example of how it works with an explanation: How to fix this script? -C solves the problem directly:

-C, --directory=DIR
              Change to DIR before performing any operations.  This option is  order-sensitive,
              i.e. it affects all options that follow.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question