大网数据广告活动
服务器运维问答

Creating backups with tar.gz and rsync

· 52CE 我爱测

I'm trying to use this bash script to create and send the tar.gz file to my backup server, some reason it doesn't seem to copy it, is there a better solution to what I'm trying to do? I'd rather have it compressed before I send i…

问题原文

原帖链接 · Killbots2012 · CC BY-SA 4.0

I'm trying to use this bash script to create and send the tar.gz file to my backup server, some reason it doesn't seem to copy it, is there a better solution to what I'm trying to do?

I'd rather have it compressed before I send it over the network

#!/bin/bash
####################################
#
# Backup to NFS mount script.
#
####################################

# What to backup. 
backup_files="/home/amp/.ampdata/instances/Towny/"

# Where to backup to.
dest="/home/amp/Backups"

# Create archive filename.
day=$(date +%A)
time=$(date +%H-%M)
file=$(file)
archive_file="$file-$day-$time.tgz"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
rsync $archive_file [email omitted]:~/backup
# Print end status message.
echo
echo "Backup finished"
date

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

Everywhere in your script you refer to $dest/$archive_file as the file you wish to create and copy, except in the rsync command that is supposed to copy it to the other host. Fix the call to rsync and try again.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-01-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。