I need to copy files from a computer folder to a network share folder. It's for a…
- User
I need to copy files from a computer folder to a network share folder. It's for a backup. Can you write a bash script that could do the task every day in 11 PM? Also the script should figure out which files are already copied.
- Assistant
Sure! Here's a sample bash script that should accomplish the task:
#!/bin/bash # Source and destination folders source_folder=/path/to/computer/folder destination_folder=/path/to/network/share/folder # Check if destination folder exists, create it if it doesn't if [ ! -d "$destination_folder" ]; then mkdir -p "$destination_folder" fi # Copy only new and modified files rsync -av --update "$source_folder" "$destination_folder" # Add a log entry echo "$(date): Backup completed" >> /var/log/backup.logTo run this script every day at 11 PM, you can use a cron job. To edit your crontab file, run
crontab -ein the terminal and add the following line:javascript
0 23 * * * /path/to/backup_script.sh
This will run the script at 11 PM every day. The
0at the beginning specifies that it should run at the exact minute (0th minute), and the*for the other fields means it should run every day of the month and every month.The
rsynccommand used in the script will only copy files that are new or have been modified since the last backup. This means you don't have to worry about copying files that are already backed up.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →