我正在使用rsync克隆从远程服务器(MT DV4.0)到本地(Ubuntu 11.10)的变化。 然后我使用下面的复制/粘贴脚本来压缩然后存档文件。
#!/bin/bash #################################### # # Backup to NFS mount script with # grandfather-father-son rotation. # #################################### # What to backup. backup_files="/home/server-backups/var/www/vhosts /home/server-backups/var/www/vhosts" # Where to backup to. dest="/home/bryan/server-tar" # Setup variables for the archive filename. day=$(date +%A) hostname=$(hostname -s) # Find which week of the month 1-4 it is. day_num=$(date +%d) if (( $day_num <= 7 )); then week_file="$hostname-week1.tgz" elif (( $day_num > 7 && $day_num <= 14 )); then week_file="$hostname-week2.tgz" elif (( $day_num > 14 && $day_num <= 21 )); then week_file="$hostname-week3.tgz" elif (( $day_num > 21 && $day_num < 32 )); then week_file="$hostname-week4.tgz" fi # Find if the Month is odd or even. month_num=$(date +%m) month=$(expr $month_num % 2) if [ $month -eq 0 ]; then month_file="$hostname-month2.tgz" else month_file="$hostname-month1.tgz" fi # Create archive filename. if [ $day_num == 1 ]; then archive_file=$month_file elif [ $day != "Saturday" ]; then archive_file="$hostname-$day.tgz" else archive_file=$week_file fi # 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 # Print end status message. echo echo "Backup finished" date # Long listing of files in $dest to check file sizes. ls -lh $dest/
每日备份似乎工作得很好,但我只得到6每日备份。 星期六不见了(这应该是每周备份运行的那一天)。 每月的备份也不见了。
我是服务器pipe理业余人员,所以任何帮助将不胜感激。 谢谢!
你的脚本似乎工作正常,但有点难以遵循; 我已经删除了一些小错误(不能移植到使用==与testing,它是=),并删除级联如果更简单的解决scheme; 它现在与纯sh一起工作。
#!/bin/sh #################################### # # Backup to NFS mount script with # grandfather-father-son rotation. # #################################### # What to backup. backup_files="/home/server-backups/var/www/vhosts /home/server-backups/var/www/vhosts" # Where to backup to. dest="/home/bryan/server-tar" # Setup variables for the archive filename. day=$(date +%A) hostname=$(hostname -s) # Find which week of the month 1-4 it is. day_num=$(date +%d) # Integer arithmetic to replace cascading ifs, but now can have 5th week week_file="$hostname-week$(expr $day_num / 7 + 1).tgz" # Find if the Month is odd or even. month_num=$(date +%m) month_file="$hostname-month$(expr 2 - $month_num % 2).tgz" # Create archive filename. if [ $day_num = 1 ]; then archive_file=$month_file elif [ $day != Saturday ]; then archive_file="$hostname-$day.tgz" else archive_file=$week_file fi # 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 # Print end status message. echo echo "Backup finished" date # Long listing of files in $dest to check file sizes. ls -lh $dest/
什么是实际问题? 在今天(星期六)运行它时,我发现它试图制作一个名为/home/bryan/server-tar/pegasus-week2.tgz的tar文件。
你惊讶于周六没有tarfile吗? 如果你想在那里,你可以做一些链接,因为它是相同的$主机名周$ {x} .tar
你能提供/ home / bryan / server-tar的ls吗?
[变化的差异在http://www.bayofrum.net/~crees/patches/sf-469087-1.diff%5D