[英]interactive bash script for backups
I wrote a bash
script to read a bunch of CSV files from a folder and create a backup file in a separate backups directory. 我编写了一个bash
脚本,以从文件夹中读取一堆CSV文件,并在单独的备份目录中创建一个备份文件。
#!/bin/sh
files=$(ls /../test/*.csv 2> /dev/null | wc -l)
if [ **"$files" != "0"** ]
then
# What to backup.
backup_files="/../test/test2"
# Where to backup to.
dest="../test/"
# Create archive filename.
day=$(date +%A)
name="some-file.csv"
archive_file="$name-day.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
echo
date
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
else
echo nothing there
break
fi
The script should go through each CSV file ( file(1).csv
, file(2).csv
, etc) and write to my backup file one by one, but the problem is that it only writes from the last file ( file(3).csv
). 该脚本应该遍历每个CSV文件( file(1).csv
, file(2).csv
等),然后逐个写入我的备份文件,但是问题是它仅从最后一个文件( file(3).csv
)。
The reason is you are not expanding the $day
variable. 原因是您没有扩展$day
变量。 Use this: 用这个:
archive_file="$name-$day.tgz"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.