diff --git a/README.md b/README.md index 7828ac3..7595ceb 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ See [Do It Yourself Backup System Using Rsync](http://www.sanitarium.net/golug/r - One machine (client) must have SSH access to the other (server) if backing up over network, without a password (pubkey) - This script is designed to be run from the machine data is being backed up from (the client) - This script requires root access on the client to backup `/` and root access on the server to be able to set correct file ownership - - In order to run this script passwordless sudo on rsync from the SSH user is required. This must be manually configured on the server. See [Editing /etc/sudoers](https://unix.stackexchange.com/questions/92123/rsync-all-files-of-remote-machine-over-ssh-without-root-user/92125#comment139116_92125) for details + - In order to run this script passwordless sudo on `rsync`, `rm` and `mv` from the SSH user is required. This must be manually configured on the server. See [Editing /etc/sudoers](https://unix.stackexchange.com/questions/92123/rsync-all-files-of-remote-machine-over-ssh-without-root-user/92125#comment139116_92125) for details - If root is not used on server all files will be owned by the user logged in via ssh which will lead to errors on restore ### Usage @@ -36,7 +36,7 @@ See [Do It Yourself Backup System Using Rsync](http://www.sanitarium.net/golug/r - Remotely `rsync-snapshot --shell ssh --dst username@myserver.com:/media/MyBackup` - It is recommended to schedule this command to run regularly in cron or alike - When scheduling this script run it is best to update `rsync-snapshot` regularly - - Execute `npm update -g rsync-snapshot` to update to latest **minor** version + - Execute `npm install -g rsync-snapshot` to update to latest version - Backups will be in a folder named by time and date (ex: `2018-02-21.19-06-26`) - Anything may be appended (manually) to folder names to add user friendly info (ex: `2018-02-21.19-06-26.createdDatabase`) as long as `.incomplete` is not appended (which is reserved for backups in progress, failed or canceled) - `ls -1 | sort -r` can be used to sort backups (most recent to least recent) @@ -73,7 +73,7 @@ See [Do It Yourself Backup System Using Rsync](http://www.sanitarium.net/golug/r - *Note: This will increase memory usage substantially (10x increase is possible)* - `--noDelete` - Don't delete existing files in `--dst` -- `rsyncPath PATH` *Defaults to* `"sudo rsync"` +- `--rsyncPath PATH` *Defaults to* `"sudo rsync"` - Command to execute rsync - If using SSH `"sudo rsync"` is recommended however it requires additional setup as a password prompt can not be asked (/etc/sudoers file must be modified to set NOPASSWD for rsync, see [Rsync over ssh without root](https://unix.stackexchange.com/questions/92123/rsync-all-files-of-remote-machine-over-ssh-without-root-user/92125#92125)) ##### Snapshot Management @@ -136,7 +136,12 @@ Rsync Does **NOT** Ensure Consistency | Rsync **May** Ensure Integrity - These warnings indicate a file has been deleted between the time rsync started and stopped executing - This does not mean the backup has failed, it is an expected warning as rsync does not take system level snapshots and data will not always be consistent - This message should be used a warning that said file may need to be backed up using a different method in order to ensure its consistency - - See Data Consistency & Integrity section for more information + - See [Data Consistency & Integrity section](https://github.com/mattlyons0/Rsync-Snapshot#data-consistency--integrity) for more information +- `opendir failed: Permission Denied` +- `send_files failed to open: Permission Denied` +- Any other permission related error + - These errors indicate there is an issue with the permissions rsync is being run with. + - rsync ### Recovery - Partial Recovery diff --git a/lib/Incrementer.js b/lib/Incrementer.js index 7100fb4..04c12fa 100644 --- a/lib/Incrementer.js +++ b/lib/Incrementer.js @@ -90,14 +90,16 @@ class Incrementer{ prepareForBackup(){ //Remove .incomplete folders, create .incomplete folder for this backup, find latest snapshot return new Promise(async (resolve, reject) => { let posixIncompleteRegex = '^.\\/[[:digit:]]{4}(-[[:digit:]]{2}){2}.(-?[[:digit:]]{2}){3}.incomplete$'; + let mv = 'sudo mv'; + let rm = 'sudo rm'; let bashCommand = `mkdir -p '${this.escapeQuotes(this.tempDest)}';`; //Make Temp Directory Path bashCommand+= `cd '${this.escapeQuotes(this.remoteDirectory)}';`; bashCommand+= `INCOMPLETE_BACKUPS='';`; //Clear out variable in case it was already set bashCommand+= `INCOMPLETE_BACKUPS=$(find . -maxdepth 1 -type d -regextype posix-extended -regex '${posixIncompleteRegex}' | sort -r | tail -n+2);`; //Incomplete backups except what we just created //If there are incomplete backups find most recent and move into current backup dir (to preserve progress) - bashCommand+= `if [ ! -z "$INCOMPLETE_BACKUPS" ]; then mv $(echo "$INCOMPLETE_BACKUPS" | head -1)/* ${this.escapeQuotes(this.tempDest)}; fi;`; - bashCommand+= `echo "$INCOMPLETE_BACKUPS" | xargs rm -rf;`; //Delete old incomplete backup folders + bashCommand+= `if [ ! -z "$INCOMPLETE_BACKUPS" ]; then ${mv} $(echo "$INCOMPLETE_BACKUPS" | head -1)/* ${this.escapeQuotes(this.tempDest)}; fi;`; + bashCommand+= `echo "$INCOMPLETE_BACKUPS" | xargs ${rm} -rf;`; //Delete old incomplete backup folders bashCommand+= `ls -1 | wc -l;`; //Folders (So we know when we got all info from ls) bashCommand+= `ls -1 | sort -r;`; //Print Folders 1 on a line most recent to least recent