efficiently-publish-to-website.html (1786B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <title>Efficiently Publish to a Website | Riaz's Website</title> 6 <link rel="stylesheet" href="/style.css"> 7 <link rel="icon" href="data:,"> 8 <meta name="description" content="How to use rsync instead of scp to transfer files to a host"> 9 <meta name="viewport" content="width=device-width, initial-scale=1"> 10 </head> 11 <body> 12 <h1>Efficiently Publish to a Website</h1> 13 <hr> 14 <article> 15 <p>I used to run the following commands to upload files to this website:</p> 16 <pre> 17 scp file1 file2 user@host: 18 scp articles/file3 user@host:/home/public/articles</pre> 19 <p>Typing out the path of the host is tedious, so rsync can be used. This command can be added to <code>.git/hooks/pre-push</code> to run on <code>git push</code>.</p> 20 <pre>rsync -rtzP --delete --exclude="*git" ~/website/ user@host:/home/public</pre> 21 <ul> 22 <li>-r: recursively</li> 23 <li>-t: transfer modification times, allowing unmodified files to be skipped</li> 24 <li>-z: compress files for uploading</li> 25 <li>-P: if a large file fails to be uploaded, continue from where it was instead of uploading its entirety</li> 26 <li>--delete: delete files from the receiving side that aren't locally present</li> 27 <li>--exclude="*git": exclude this pattern from uploading and following rules like --delete</li> 28 </ul> 29 <p>The slash after the folder name is there for uploading the contents of the folder and not the folder itself. Without the slash, it would result in <code>/home/public/website</code>.</p> 30 <p>I wrote the following in <code>.ssh/config</code>, allowing me to run <code>ssh riazj</code> or <code>rsync file riazj:</code>.</p> 31 <pre> 32 Host riazj 33 Hostname nfsnssh.com 34 User riazpy_riazj 35 Port 22</pre> 36 </article> 37 <footer> 38 <hr> 39 <a href="/">Home Page</a></footer> 40 </body> 41 </html>