I followed this question: How to backup filesystem with tar using a bash script?
But when I run the script it gives following error:
: not found/backup.sh: 2: /etc/init.d/backup.sh:
: not found/backup.sh: 5: /etc/init.d/backup.sh:
: not found/backup.sh: 7: /etc/init.d/backup.sh:
: not found/backup.sh: 10: /etc/init.d/backup.sh:
: not found/backup.sh: 12: /etc/init.d/backup.sh:
/etc/init.d/backup.sh: 13: /etc/init.d/backup.sh: Syntax error: "(" unexpected
Here's my script:
#!/bin/bash
#TODAY=$(date +%F)
#HOST=$(hostname)
mybackupname="backup-fullsys-$(date +%Y-%m-%d).tar.gz"
# Record start time by epoch second
start=$(date '+%s')
# List of excludes in a bash array, for easier reading.
excludes=(--exclude=/FILES/Media/Programs/Mint/Backup/$mybackupname)
excludes+=(--exclude=/proc)
excludes+=(--exclude=/lost+found)
excludes+=(--exclude=/sys)
excludes+=(--exclude=/mnt)
excludes+=(--exclude=/MEDIA)
excludes+=(--exclude=/BACKUP)
excludes+=(--exclude=/FILES)
if ! tar -czf "$mybackupname" "${excludes[@]}" /; then
status="tar failed"
elif ! mv "$mybackupname" FILES/Media/Programs/Mint/Backup/ ; then
status="mv failed"
else
status="success: size=$(stat -c%s backups/filesystem/$mybackupname) duration=$((`date '+%s'` - $start))"
# Log to system log; handle this using syslog(8).
logger -t backup "$status"
Anyone see where I'm going wrong here?
As "That other guy" commented the solution here was to run the dos2unix convert command on the bash file:
and running it using bash command not sh command: