T
T
tgarl2021-06-07 16:08:50
linux
tgarl, 2021-06-07 16:08:50

Why can't I see the folder or file?

there is a file

#!/bin/bash
tar --exclude='./bitrix'  --exclude='./upload' -vhczf /root/backup/`basename $PWD`-`date '+%Y%m%d'`.tar.gz .


I go to the folder I want to archive
cd /../../../...

call sourse full_path_to_file

in response
tar: .\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
tgarl, 2021-06-08
@tgarl

In my case, the solution is Lynn's comment "Coffeeman"

Resave file with UNIX line endings

Resave and everything worked.
Viktor Taran , thanks for the script

V
Victor Taran, 2021-06-08
@shambler81

creating a backup
60be967c5f0f0182040362.png
The structure of backups (here the FTP server is mounted via cifs)
60be97a6eedb8875107169.png
works like this: if you run the script, it backups all sites with all databases, excludes everything that is needed. (each site backs up its database separately) well, each site separately.
if you specify a site through a space, then scrypt.sh vasya.ruonly it is backed up, it is also immediately uploaded to FTP with a
speed limit and a progress bar.
and cleanup of local backups
Also, after the backup, a direct link to the FTP archive is thrown out to you.
additional software wput and pv it needs to be delivered!

#!/bin/sh
# Пример пути до сайта /var/www/site.ru/web/
SITEDIR="/home/bitrix/ext_www"                      # Папка до названия доменаов
DBCONN="bitrix/php_interface/dbconn.php"            # Откуда читать настройки mysql
FTPUSER="backup_ftp"                                # Логин FTP сервера
FTPPASS="adfadsfasdfa safdw"                        # Пароль FTP
FTPHOST="111.1.11.11    "                           # сервер FTP
FTPDIR=""                                           # папка на FTP
TMPDIR="/mnt/backup/site"                           # тут временный файл лежит до отправки
TMPWPUTBASE="/mnt/backup"                            # wput подставит эту папку как базовую
DATE=`date +"%Y-%m-%d"`                             # Формат даты в имени файла
DATEYM=`date +%Y`/`date +%m`                        # Второй форматы даты
LIST=${1:-`ls $SITEDIR | grep -E ".*\.\w{1,5}" | grep -v "restore.php" | grep -v "klondike.php"`} # Название сайта, тут выбор или аргумент или, регулярка  можно убрать только -L ;)

mkdir -p $TMPDIR/$DATEYM # создаем  структ уру каталогов если их нет

for ELEMENT in $LIST
    do
                if [ ! -f /$SITEDIR/$ELEMENT/$DBCONN ];
                        then
                            echo " Файл $SITEDIR/$ELEMENT/$DBCONN не найден, сайт будет без БД!"
                        else
# ищим какая база отностися к сайту сохраняем в переменные ее данные.
DBLOGIN=$(/bin/php -r "include '${SITEDIR}/${ELEMENT}/${DBCONN}'; echo(\"{\$DBLogin}\");")
DBNAME=$(/bin/php -r "include '${SITEDIR}/${ELEMENT}/${DBCONN}'; echo(\"{\$DBName}\");")
DBPASS=$(/bin/php -r "include '${SITEDIR}/${ELEMENT}/${DBCONN}'; echo(\"{\$DBPassword}\");")
DBHOST=$(/bin/php -r "include '${SITEDIR}/${ELEMENT}/${DBCONN}'; echo(\"{\$DBHost}\");")
echo "Найдена BD $ELEMENT"
echo ""
echo "Login: $DBLOGIN"
echo "DB   : $DBNAME"
echo "Pass : $DBPASS"
echo "Host : $DBHOST"
echo ""
echo "Дамп БД $DBNAME"

#  бэкап базы только через эвал и эхо смогли экранировать все варианты спецсимволов в пароле
eval "$(echo "mysqldump --no-tablespaces -u$DBLOGIN -p'$DBPASS' $DBNAME -h$DBHOST > $SITEDIR/$ELEMENT/$DBNAME\-$DATE.sql  && echo "Дамп БД $DBNAME будет сохранен в корне сайта"  ||  echo "Ошибка дампа базы данных " $DBNAME")"
chown bitrix:bitrix $SITEDIR/$ELEMENT/$DBNAME\-$DATE.sql
               fi

echo "Считаем количество Файлов  на сайте"

SIZE="$(find $SITEDIR/$ELEMENT/$WEB -not -path "$SITEDIR/$ELEMENT/bitrix/tmp/*" -not -path "$SITEDIR/$ELEMENT/bitrix/updates/*" -not -path "$SITEDIR/$ELEMENT/dev_logs/*" -not -path "$SITEDIR/$ELEMENT/upload/1c_import_light/logs/*" -not -path "$SITEDIR/$ELEMENT/upload/1c_import_light/total_errors/*" -not -path "$SITEDIR/$ELEMENT/.git/*" -not -path "$SITEDIR/$ELEMENT/bitrix/catalog_export/logs/*" -not -path "$SITEDIR/$ELEMENT/bitrix/backup/*" -not -path "$SITEDIR/$ELEMENT/bitrix/cache/*" -not -path "$SITEDIR/$ELEMENT/bitrix/managed_cache/*" -not -path "$SITEDIR/$ELEMENT/bitrix/stack_cache/*" -not -path "$SITEDIR/$ELEMENT/upload/resize_cache/*" -not -path "$SITEDIR/$ELEMENT/stats/*" | wc -l)" && echo " В архиве будет $SIZE файлов"

echo "Архивируем сайт $ELEMENT прогресс не в килобайтах а в  количестве файлов"
tar -cvpzf $TMPDIR/$DATEYM/$ELEMENT-$DATE.tar.gz --directory $SITEDIR/$ELEMENT/$WEB --ignore-failed-read --exclude='./bitrix/tmp' --exclude='./bitrix/updates'  --exclude='./dev_logs' --exclude='./upload/1c_import_light/logs' --exclude='./upload/1c_import_light/total_errors' --exclude='./.git' --exclude='./bitrix/catalog_export/logs'  --exclude='./bitrix/backup'  --exclude='./bitrix/cache' --exclude='./bitrix/managed_cache' --exclude='./bitrix/stack_cache' --exclude='./upload/resize_cache' --exclude='./stats' . | pv -s $SIZE -l > /dev/null

        rm -f $SITEDIR/$ELEMENT/$WEB/$DBNAME\-$DATE.sql # поскльку ложим на реальный сайт, ибо нормально добавить в архив не получитяс.

        echo "Сохраняем $ELEMENT на FTP"
        wput  --basename=$TMPWPUTBASE --limit-rate=6000K --timestamping  --remove-source-files --tries=2 $TMPDIR/$DATEYM/$ELEMENT-$DATE.tar.gz ftp://$FTPUSER:$FTPPASS@$FTPHOST$FTPDIR && echo "Архив залит успешно, временные файлы удалены"

echo -en "\n\033[37;1;41m Ссылочка:\033[0m \e[1;4;36mwget ftp://$FTPUSER:$FTPPASS@$FTPHOST/site/$DATEYM/$ELEMENT-$DATE.tar.gz\e[0m\n\n" #ks05

  done

rm -r $TMPDIR

The script does not use the Bitrix VM core so that it can be adapted to any other servers. To determine the database, dbconn is executed and its variables are used for backup.

L
link_vrb, 2021-06-07
@link_vrb

swears at . \ r means this is an error, discard the pzh command

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question