0

Okay so essentially what I'm doing, is I'm taking all the directories inside of the /servers/ folder, and moving them to a secondary hard drive mounted at /media/backupdrive/. This script is ran once a day, so it makes the directory with the name of the date, and should copy the folders directly over there (The reason I have to do it this way is because my client has limited disk space on his main hard drive and his worlds are upwards of 6-7gb each). Anyway, I can get them to copy the folders to /media/backupdrive/currentdate, but then when I try to compress it, it says it can't compress an empty directory or something along the lines of that.

Here's the code:

#!bin/bash
folderName=$(date +"%m-%d-%y")
mkdir "/media/backupdrive/$folderName"

for i in servers/*; do
    cp -rf $i /media/backupdrive/$folderName/
    cd /media/backupdrive/$folderName/
    tar -C ${i:8} -czvf "${i:8}.tar.gz"
    cd /root/multicraft/
done

Sorry for the image, it was on a virtual machine and I had to re-type it, because I couldn't copy and paste.

4

2 回答 2

3

在我看来,您的 tar 命令缺少其输入(例如,最后的“.”),因此说,“tar:懦弱地拒绝创建空存档”。

使用此 tar 命令,您的脚本似乎对我有用:

tar -C ${i#servers/} -czvf "${i#servers/}.tar.gz" .
于 2013-03-19T21:19:14.000 回答
1

我会尝试一种稍微不同的方法。tar本身不使用临时文件,因此您可以tar将源直接发送到目标并在第二步中压缩它们gzip

#!bin/bash

dst="/media/backupdrive/$(date +"%m-%d-%y")"

for d in servers/*; do
  tarfile="$dst/${d#servers/}.tar"
  tar -C "$d" -cvf "$tarfile" .
  gzip -9 "$tarfile"
done
于 2013-03-19T22:33:54.137 回答